VBA 幻灯片。如何在VBA中获取文件的当前目录路径?



VBA Powerpoint.如何设置环境当前目录?

我也尝试了这段代码:

Sub test()
Dim sPath As String
sPath = ActiveWorkbook.Path
MsgBox sPath
End Sub

但说:Object required

请帮助我使其工作...

Tim提供了答案。活动演示文稿的文件路径存储在属性 ActivePresentation.Path 中。如果演示文稿文件尚未保存,此属性将包含一个空字符串。要对此进行测试,您可以使用以下内容:

Sub test()
    Dim sPath As String
    sPath = ActivePresentation.Path
    If Len(sPath) > 0 Then
        MsgBox ActivePresentation.Name & vbNewLine & "saved under" & vbNewLine & sPath
    Else
        MsgBox "File not saved"
    End If
End Sub

请注意,这是一个只读属性。 您无法设置此变量。

https://learn.microsoft.com/en-us/office/vba/api/powerpoint.presentation.path

最新更新