PDA

View Full Version : PPT Master slide VBA help



Ayla1427
11-10-2023, 01:51 AM
Hi, I am trying to create a macro that will re-insert master slides from a template from a location on the network, in case people delete them, I have the code below, it seems to work and run fine, but when you go into the master the slides aren’t added. I am not fully confident in vba so need a little help if possible

Thanks in advance


Sub CopyMasterSlidesFromNetwork() ' Specify the path to the PowerPoint file on the network
Dim sourceFilePath As String
sourceFilePath = "\\Network\Path\To\Your\Source\File.pptx" ' Replace with the actual network path
' Open the source presentation
Dim sourcePresentation As Presentation
Set sourcePresentation = Presentations.Open(sourceFilePath)
' Copy master slides from the source presentation
Dim slideIndex As Integer
For slideIndex = 1 To sourcePresentation.Slides.Count
sourcePresentation.Slides(slideIndex).CustomLayout.Copy
ActivePresentation.Designs(1).SlideMaster.CustomLayouts.Paste
Next slideIndex
' Close the source presentation without saving changes
sourcePresentation.Close False
End Sub

jdelano
11-10-2023, 03:25 AM
Maybe try using this command instead
ActivePresentation.Slides.InsertFromFile FileName:="source.pptm", Index:=1, SlideStart:=2, SlideEnd:=4 Slides.InsertFromFile method (PowerPoint) | Microsoft Learn (https://learn.microsoft.com/en-us/office/vba/api/PowerPoint.Slides.InsertFromFile)

Ayla1427
11-10-2023, 06:33 AM
Maybe try using this command instead
ActivePresentation.Slides.InsertFromFile FileName:="source.pptm", Index:=1, SlideStart:=2, SlideEnd:=4 Slides.InsertFromFile method (PowerPoint) | Microsoft Learn (https://learn.microsoft.com/en-us/office/vba/api/PowerPoint.Slides.InsertFromFile)


thanks for the code, this looks like it’s just inserting slides rather than the masters, is that right? I am a newbie to vba, apologies if not

John Wilson
11-13-2023, 07:54 AM
To get back to the original problem:

Are you saying that users are physically deleting custom layouts OR they delete a slide and the corresponding layout also deletes OR something else.

Ayla1427
11-15-2023, 04:12 AM
To get back to the original problem:

Are you saying that users are physically deleting custom layouts OR they delete a slide and the corresponding layout also deletes OR something else.


yes so sometimes users go into the masters and delete them due to file size increasing, however I would like to be able to apply the template to the current file, which then re-inserts the master slides of the template