Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA Powerpoint. How to get file's current directory path to a string in VBA?

Tags:

powerpoint

vba

VBA Powerpoint. How can i set environment current directory?

I also tried this code:

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

But is says: Object required

Please help me to make it work ...

like image 1000
Andrei20193 Avatar asked Sep 22 '12 17:09

Andrei20193


People also ask

How do I view the VBA code in PowerPoint?

Here's how you can find macros and VBA modules in your document: In Word or Excel, click View > Macro > View Macros. In PowerPoint, click View > Macro.


1 Answers

Tim has provided the answer. The file path of the active presentation is stored in the property, ActivePresentation.Path. If the presentation file has not been saved yet this property will contain an empty string. To test this out you could use something like:

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

Note that this is a read-only property. You can't set this variable.

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

like image 71
brettdj Avatar answered Sep 20 '22 19:09

brettdj