Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- When the Macro works
- 1. I open a Powerpoint presentation without Macro
- 2. Powerpoint presentation with Macro
- 3. The Macro works, it merges multiple Powerpoints into my Active presentation
- When the Macro does not work
- 1. I open Powerpoint presentation with Macro
- 2. The Macro does not work, it does not merge multiple Powerpoints into my Active presentation
- Sub RunPowerPointMacro()
- Dim objPP As Object
- Dim objPPFile As Object
- Set objPP = CreateObject("PowerPoint.Application")
- objPP.Visible = True
- Set objPPFile = objPP.Presentations.Open("\sthpv0003anhi14$My ConfigUserDataDesktopTPPresentation1.pptm")
- Application.EnableEvents = False
- objPP.Run "Presentation1.pptm!Module1.InsertFromList"
- Application.EnableEvents = True
- 'objPPFile.Close
- Set objPPFile = Nothing
- Set objPP = Nothing
- End Sub
- Sub InsertFromList()
- ' Inserts all presentations named in LIST.TXT into current presentation
- ' in list order
- ' LIST.TXT must be properly formatted, one full path name per line
- On Error GoTo ErrorHandler
- Dim sListFileName As String
- Dim sListFilePath As String
- Dim iListFileNum As Integer
- Dim sBuf As String
- ' EDIT THESE AS NEEDED
- ' name of file containing files to be inserted
- sListFileName = "LIST.TXT"
- ' backslash terminated path to filder containing list file:
- sListFilePath = "\FilePathUserDataDesktopTP"
- ' Do we have a file open already?
- If Not Presentations.Count > 0 Then
- Exit Sub
- End If
- ' If LIST.TXT file doesn't exist, create it
- If Len(Dir$(sListFilePath & sListFileName)) = 0 Then
- iListFileNum = FreeFile()
- Open sListFilePath & sListFileName For Output As iListFileNum
- ' get file names
- sBuf = Dir$(sListFilePath & "*.PPTX")
- While Not sBuf = ""
- Print #iListFileNum, sBuf
- sBuf = Dir$
- Wend
- Close #iListFileNum
- End If
- iListFileNum = FreeFile()
- Open sListFilePath & sListFileName For Input As iListFileNum
- ' Process the list
- While Not EOF(iListFileNum)
- ' Get a line from the list file
- Line Input #iListFileNum, sBuf
- ' Verify that the file named on the line exists
- If Dir$(sBuf) <> "" Then
- Call ActivePresentation.Slides.InsertFromFile( _ <<< Change this one?
- sBuf, ActivePresentation.Slides.Count)
- End If
- Wend
- Close #iListFileNum
- NormalExit:
- Exit Sub
- ErrorHandler:
- Call MsgBox("Error:" & vbCrLf & Err.Number & vbCrLf & Err.Description, _
- vbOKOnly, "Error inserting files")
- Resume NormalExit
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement