vba - 如何从Application.Path获取UNC路径?

标签 vba

我想在 vba 代码中获取事件工作簿的路径。 ActiveWorkbook.Path 执行此操作

但是

我需要它来检索这样的东西:

\\MachineName\ShareFolder\ETC\ETC2

不是:

S:\ETC\ETC2

其中 S: 映射到 \\MachineName\ShareFolder\。我该怎么做?

最佳答案

    Dim Drive As String
    Drive = Left(ActiveWorkbook.Path, 2)

    ActiveWorkbookPath = Replace(ActiveWorkbook.Path, Drive, GetNetworkPath(Drive))


Function GetNetworkPath(ByVal DriveName As String) As String

    Dim objNtWork  As Object
    Dim objDrives  As Object
    Dim lngLoop    As Long


    Set objNtWork = CreateObject("WScript.Network")
    Set objDrives = objNtWork.enumnetworkdrives

    For lngLoop = 0 To objDrives.Count - 1 Step 2
        If UCase(objDrives.Item(lngLoop)) = UCase(DriveName) Then
            GetNetworkPath = objDrives.Item(lngLoop + 1)
            Exit For
        End If
    Next

End Function

关于vba - 如何从Application.Path获取UNC路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47908572/

相关文章:

excel - 在Excel中用vba声明unicode字符串

ms-access - 如何使用 VBA 刷新导航 Pane

excel - 删除单元格内的值

vba - 如何使用 VBA 调用 Microsoft Graph API?

vba - 字自动化 : Write RTF text without going through clipboard

vba - 将选定单元格的导出写入不带 "quotation marks"的 .txt 文件

excel - 如何使用格式化指数和分数的 oMaths 创建 Word VBA 方程?

excel - 如何自动筛选第二行

vba - Excel VBA : Add a scatter chart to worksheet as object

vba - Excel - 通过 VBA 显示组合框下拉菜单