user181796
user181796

Reputation: 195

Macro to open all PPT files

I created the following macro to open all ppt files in a certain map

Sub openAllPPT()
    Dim strCurrentFile As String
    Dim strFileSpec As String

    strFileSpec = "C:\Documents and Settings\aa471714\Desktop\Nieuwe map*.ppt"
    strCurrentFile = Dir$(strFileSpec)

    While Len(strCurrentFile) > 0
          Presentations.Open (strCurrentFile)
          strCurrentFile = Dir$
    Wend

End Sub

When I run it I do see anything opening up though. Anybody clue on what I'm missing?

Upvotes: 0

Views: 1095

Answers (1)

Steve Rindsberg
Steve Rindsberg

Reputation: 14810

Dir returns only the file name, not the full path to the file. Try this instead:

Sub openAllPPT()

    Dim strCurrentFile As String
    Dim strFileSpec As String
    Dim strDirectory As String

    strDirectory = "C:\Documents and Settings\aa471714\Desktop\"
    strFileSpec = "Nieuwe map*.ppt"

    strCurrentFile = Dir$(strDirectory & strFileSpec)

    While Len(strCurrentFile) > 0
          'Presentations.Open (strDirectory & strCurrentFile)
          Debug.Print strDirectory & strCurrentFile
          strCurrentFile = Dir$
    Wend

End Sub

Upvotes: 3

Related Questions