如何在macros编程中获取当前目录名称?

我需要知道如何在macros编程中获取当前目录variables。 我像这样在桌面上保存文件:C:\ Users \ deadlock \ Desktop \ data.html。 是否有可能取代C:\用户\死锁\桌面\当前直接variables?

这是我的一小段代码:

ActiveWorkbook.ShowPivotChartActiveFields = True With ActiveWorkbook.PublishObjects.Add(xlSourceSheet, _ "C:\Users\deadlock\Desktop\data.htm", "Sheet1", "", xlHtmlStatic, "data_9438", "") .Publish (True) .AutoRepublish = False 

任何代码片段将高度赞赏。

提前致谢..

当前目录通过VBA的curdir()和通过ActiveWorkbook.Path当前工作簿的目录。

编辑;

 Dim current As String current = CurDir$() '// root dirs have a \ others do not; normalize If Right$(current, 1) <> "\" Then current = current & "\" With ActiveWorkbook.PublishObjects.Add(xlSourceSheet, _ current & "data.htm", "Sheet1", "", xlHtmlStatic, "data_9438", "") .Publish (True) .... 

是可以用当前直接variablesreplaceC:\用户\死锁\桌面\ \?

这是你正在尝试?

 Option Explicit Sub Sample() Dim strPath As String Dim Myar As Variant strPath = "C:\Users\deadlock\Desktop\data.htm" Myar = Split(strPath, "\") '~~> This would give you something like '~~> C:\Users\Siddharth Rout\Documents\data.htm Debug.Print CurDir & "\" & Myar(UBound(Myar)) End Sub