Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. When the Macro works
  2.  
  3. 1. I open a Powerpoint presentation without Macro
  4. 2. Powerpoint presentation with Macro
  5. 3. The Macro works, it merges multiple Powerpoints into my Active presentation
  6.  
  7. When the Macro does not work
  8.  
  9. 1. I open Powerpoint presentation with Macro
  10. 2. The Macro does not work, it does not merge multiple Powerpoints into my Active presentation
  11.  
  12. Sub RunPowerPointMacro()
  13.  
  14. Dim objPP As Object
  15. Dim objPPFile As Object
  16.  
  17. Set objPP = CreateObject("PowerPoint.Application")
  18. objPP.Visible = True
  19.  
  20. Set objPPFile = objPP.Presentations.Open("\sthpv0003anhi14$My ConfigUserDataDesktopTPPresentation1.pptm")
  21.  
  22.  
  23.  
  24. Application.EnableEvents = False
  25.  
  26. objPP.Run "Presentation1.pptm!Module1.InsertFromList"
  27.  
  28. Application.EnableEvents = True
  29.  
  30. 'objPPFile.Close
  31.  
  32. Set objPPFile = Nothing
  33. Set objPP = Nothing
  34.  
  35. End Sub
  36.  
  37.  
  38.  
  39. Sub InsertFromList()
  40. ' Inserts all presentations named in LIST.TXT into current presentation
  41. ' in list order
  42. ' LIST.TXT must be properly formatted, one full path name per line
  43.  
  44. On Error GoTo ErrorHandler
  45.  
  46. Dim sListFileName As String
  47. Dim sListFilePath As String
  48. Dim iListFileNum As Integer
  49. Dim sBuf As String
  50.  
  51. ' EDIT THESE AS NEEDED
  52. ' name of file containing files to be inserted
  53.  
  54. sListFileName = "LIST.TXT"
  55.  
  56. ' backslash terminated path to filder containing list file:
  57. sListFilePath = "\FilePathUserDataDesktopTP"
  58.  
  59. ' Do we have a file open already?
  60. If Not Presentations.Count > 0 Then
  61. Exit Sub
  62. End If
  63.  
  64. ' If LIST.TXT file doesn't exist, create it
  65. If Len(Dir$(sListFilePath & sListFileName)) = 0 Then
  66. iListFileNum = FreeFile()
  67. Open sListFilePath & sListFileName For Output As iListFileNum
  68. ' get file names
  69. sBuf = Dir$(sListFilePath & "*.PPTX")
  70. While Not sBuf = ""
  71. Print #iListFileNum, sBuf
  72. sBuf = Dir$
  73. Wend
  74. Close #iListFileNum
  75. End If
  76.  
  77. iListFileNum = FreeFile()
  78. Open sListFilePath & sListFileName For Input As iListFileNum
  79. ' Process the list
  80. While Not EOF(iListFileNum)
  81. ' Get a line from the list file
  82. Line Input #iListFileNum, sBuf
  83.  
  84. ' Verify that the file named on the line exists
  85. If Dir$(sBuf) <> "" Then
  86. Call ActivePresentation.Slides.InsertFromFile( _ <<< Change this one?
  87. sBuf, ActivePresentation.Slides.Count)
  88. End If
  89. Wend
  90.  
  91. Close #iListFileNum
  92.  
  93. NormalExit:
  94. Exit Sub
  95. ErrorHandler:
  96. Call MsgBox("Error:" & vbCrLf & Err.Number & vbCrLf & Err.Description, _
  97. vbOKOnly, "Error inserting files")
  98. Resume NormalExit
  99. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement