Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

vba - Apply layout on existing slides

I would like to apply the layout to existing slides in ppt. Below coding is creating new sides and applying the layout. Can someone please assist me on this. I dont want to create new slide. I just want to apply layout to existing slides.

Set ppt = CreateObject("PowerPoint.Application")
  Set myPres = ppt.Presentations.Open(pptName)

For i = 1 To 10
   Set slds = myPres.Slides
   Set sld = slds.Add(myPres.Slides.Count + 1, ppLayoutBlank)
   For Each oLayout In myPres.Designs("Office Theme").SlideMaster.CustomLayouts
       If oLayout.Name = "Title and Content" Then
           sld.CustomLayout = oLayout
           Exit For
       End If
   Next
Next i
question from:https://stackoverflow.com/questions/65914707/apply-layout-on-existing-slides

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Set ppt = CreateObject("PowerPoint.Application")
  Set myPres = ppt.Presentations.Open(pptName)

'For i = 1 To 10
'   Set slds = myPres.Slides
'   Set sld = slds.Add(myPres.Slides.Count + 1, ppLayoutBlank)
For each sld in myPres.Slides
   For Each oLayout In myPres.Designs("Office Theme").SlideMaster.CustomLayouts
       If oLayout.Name = "Title and Content" Then
           sld.CustomLayout = oLayout
           Exit For
       End If
   Next
'Next i

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...