VBA PowerPoint. 如何在VBA中将文件所在目录路径转换为字符串?

8

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

我也尝试了这段代码:

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

但是它显示:需要对象

请帮我让它工作起来...


10
ActivePresentation.Path - Tim Williams
1个回答

15

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接