I have 500,000 slides across 55,000 presentations. I would like to add a picture to each slide.
I can open the presentations from Excel however I then have to manually add a macro to one of the presentations and set it to loop through.
I found that opening 50 presentations at a time stops the system from crashing out of memory. This is laborious. I would like to open each file run the macro, close the file and use Excel to loop through all the files.
Code to open the file.
Sub Open_PPT_Irregular_Files()
Dim arrPPTFiles(500) As Variant 'Change value to amount of presentations
Dim DestinationPPT As String
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Dim i, v, w, x, y, z As Integer
Dim strT As String
v = 500 'Change value to amount of presentations
w = 0 'Halting position to stop running out of memory
x = 1 'Starting cell position update as required
y = 9 'Ending cell position update as required
Dim arrPPT(500) As Variant 'Change value to amount of presentations
Sheets("PPTIrregular").Select
'I hold the path to all the presentations on this sheet.... populated from a recursive query
For i = 1 To v
arrPPT(i) = Range("A" & i).Value2
Next
Set PowerPointApp = CreateObject("PowerPoint.Application")
For i = 1 To v
DestinationPPT = arrPPT(i) '"path"
PowerPointApp.Presentations.Open (DestinationPPT)
PowerPointApp.ActiveWindow.WindowState = ppWindowMinimized
'Application.Run "Copyright.xlsm!Paste_CopyrightPPT.Paste_CopyrightPPT"
If w = 50 Then
'at this point i select manually a presentation and then import the macro to it and loop x 50 times
'before continuing the code for next 50 etc...
Stop
w = 0
End If
w = w + 1
Next
End Sub
Code to run the PowerPoint macro I add manually.
Sub callCopyRight()
For i = 1 To 50
Call Paste_CopyrightPPT
Next
End Sub
Sub Paste_CopyrightPPT()
'PowerPoint Macro Only! Not tested in excel yet.
' In order to run this code first make sure the logo exists in objImageBox
Dim i, y, z As Integer
Dim objPresentaion As Presentation
Dim objSlide As Slide
Dim objImageBox As Shape
i = 2
y = ActivePresentation.Slides.Count
z = 2
For i = 1 To y
Set objPresentaion = ActivePresentation
Set objSlide = objPresentaion.Slides.Item(i)
'Storing the picture below...
Set objImageBox = objSlide.Shapes.AddPicture("C:\Users\Gazza\Desktop\_MasterBreakdowns '\Copyright.jpg", msoCTrue, msoCTrue, 100, 100)
objSlide.Shapes.Item(2).Top = 1
objSlide.Shapes.Item(2).Left = 1
objSlide.Shapes.Item(2).Width = 60
objSlide.Shapes.Item(2).Height = 15
Next
PowerPoint.ActivePresentation.Slides(1).Select
PowerPoint.ActivePresentation.Save
PowerPoint.ActivePresentation.Close
End Sub
I need to run a variation of this code from Excel on a presentation by presentation basis.