Search code examples
vbapowerpointclipboard

In power point how can I populate pasteboard with a path to a folder


I need to save a file to a specific folder. I have to click through a path. too many clicks

I want to create a button in power point slide. Clicking this button would copy the folder path on the clipboard. The the next button on the slide opens a word file and I press save as and paste the path to east my navigational nightmare.

I have created a power point slide.

Placed a few images and made them clickable.

Each click opens a certain file or folder.

Now I want a file X to be copied to a specific folder. Clicking a button opens the file X but to save a copy of the same to a specific folder I have to navigate again.

any solution?


Solution

  • As long as you don't mind having to include the macro in every presentation, or saving it in another file that you open whenever you want to use it on the current active presentation:

    Sub CopyPath()
        Dim oShp As Shape
        
        If Len(ActivePresentation.Path) = 0 Then
            MsgBox "Please save your presentation, then try again"
        Else
            Set oShp = ActivePresentation.Slides(1).Shapes.AddTextbox(msoTextOrientationHorizontalRotatedFarEast, 0, 0, 0, 0)
            oShp.TextFrame.TextRange.Text = ActivePresentation.Path & "\"
            oShp.TextFrame.TextRange.Copy
            oShp.Delete
        End If
    End Sub
    

    Or to use a fixed path, per your comment below:

    Sub CopyPath()
        Dim oShp As Shape
        Dim sPath as String
    
        ' EDIT THIS to be whatever path you like
        sPath = "C:\Temp\MyStuff\Goes\Here\"
    
        If Len(ActivePresentation.Path) = 0 Then
            MsgBox "Please save your presentation, then try again"
        Else
            Set oShp = ActivePresentation.Slides(1).Shapes.AddTextbox(msoTextOrientationHorizontalRotatedFarEast, 0, 0, 0, 0)
            oShp.TextFrame.TextRange.Text = sPath
            oShp.TextFrame.TextRange.Copy
            oShp.Delete
        End If
    End Sub
    

    You'd need to save this in a PPTM rather than PPTX file. As long as the file's open you can use ALT+F8 to access it.