VBA Powerpoint. 我该如何设置环境当前目录?
我也尝试了这段代码:
Sub test()
Dim sPath As String
sPath = ActiveWorkbook.Path
MsgBox sPath
End Sub
但是它显示:需要对象
请帮我让它工作起来...
VBA Powerpoint. 我该如何设置环境当前目录?
我也尝试了这段代码:
Sub test()
Dim sPath As String
sPath = ActiveWorkbook.Path
MsgBox sPath
End Sub
但是它显示:需要对象
请帮我让它工作起来...
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