首页 > 解决方案 > VB.NET 中的 VBA 等效项

问题描述

我有一个在 excel 中工作的 VBA 模块,当我将其转换为 VB.net 时,我收到错误“UNC 路径的格式应为 \\server\share。”

VBA Excel模块1:

   Global MyFolder As String
   Global MyFile As Variant
   Global eRow As Long
   Global Crow As Long

   Public Sub Browsing()
   With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
    .Show
    MyFolder = .SelectedItems(1) & "\"
    Err.Clear
   End With
   MyFile = Dir(MyFolder & "\", vbReadOnly)
End Sub

转换后的 VB.net 代码模块 1

Imports System.IO
Imports Excel = Microsoft.Office.Interop.Excel
Module Module1
    Public MyFolder As String
    Public MyFile As VariantType
    Public eRow As Long
    Public Crow As Long
    Public Sub Browsing()
        Dim xl As New Excel.Application
        With xl.Application.FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFolderPicker)
            .AllowMultiSelect = False
            .Show()
            MyFolder = .SelectedItems(1) & "\"
            Err.Clear()
        End With
        **MyFile = Dir(MyFolder & "\", FileAttribute.ReadOnly)**
    End Sub
End Module

错误:“UNC 路径的格式应为 \\server\share。”

感谢你的帮助

感谢和问候

莫赫布·拉比

标签: excelvbavb.netpathunc

解决方案


推荐阅读