jolodali
asked on
How do I write VBA to copy a slide's title to a new slide?
I need to insert a blank slide after every existing slide in a Powerpoint presentation. I would like each of these new slides to have the same title as the previous slide (It's purpose is to explain the previous slide). In addition, each existing slide has a text box in its upper right corner that has a sequence number that I manually typed in. It's not the actual sequence number - i.e., it doesn't start at 1. I would like the new slide to copy the text box and value and append it with an "a" - e.g., 11a, 12a
The following code is working to add the new slide (I don't mind manually selecting each slide before running the code). Could anyone help with the code to copy the title and sequence number text box? thanks.
Sub InsertSlide()
Dim oView As View
With ActivePresentation.Slides
Set oView = ActiveWindow.View
oView.GotoSlide .Add(oView.Slide.SlideInde x + 1, _
ppLayoutTitleOnly).SlideIn dex
Set oView = Nothing
End With
End Sub
The following code is working to add the new slide (I don't mind manually selecting each slide before running the code). Could anyone help with the code to copy the title and sequence number text box? thanks.
Sub InsertSlide()
Dim oView As View
With ActivePresentation.Slides
Set oView = ActiveWindow.View
oView.GotoSlide .Add(oView.Slide.SlideInde
ppLayoutTitleOnly).SlideIn
Set oView = Nothing
End With
End Sub
Inserting the slides and copying the titlrs seems fine with the following, however can you advise how to recognise the text box with the sequence number in order to address that bit.
Chris
Chris
Sub insertSlides()
Dim pptView As View
Dim sld As Slide
Dim sldNum As Integer
Dim newbie As Slide
With ActivePresentation
For sldNum = .Slides.Count To 1 Step -1
Set sld = .Slides(sldNum)
Set newbie = .Slides.Add(Index:=sldNum + 1, Layout:=ppLayoutTitleOnly)
newbie.Shapes.Title.TextFrame.TextRange = sld.Shapes.Title.TextFrame.TextRange
' Debug.Print sld.Shapes.Title.TextFrame.TextRange
Next
End With
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Using code to name your shape:
http://www.pptfaq.com/FAQ00584.htm
However I think a better approach would be to simply copy the entire slide and then modify the "seqence box" contents and delete the placeholder contents. That way you retain the specific layout of the slide.
With ActivePresentation.Slides( 1)
'Create a duplicate of the slide.
Set Sl = .Duplicate
However, if you don't mind selecting each slide bfore running the code, you can easily insert a copy of each slide by clicking on Insert, Duplicate Slide. Or if you prefer keystrokes, ALT-I, D
Some more about VB coding in PowerPoint:
http://www.pptfaq.com/index.html#name_For_VBeginners
http://skp.mvps.org/vba.htm
http://www.pptfaq.com/FAQ00584.htm
However I think a better approach would be to simply copy the entire slide and then modify the "seqence box" contents and delete the placeholder contents. That way you retain the specific layout of the slide.
With ActivePresentation.Slides(
'Create a duplicate of the slide.
Set Sl = .Duplicate
However, if you don't mind selecting each slide bfore running the code, you can easily insert a copy of each slide by clicking on Insert, Duplicate Slide. Or if you prefer keystrokes, ALT-I, D
Some more about VB coding in PowerPoint:
http://www.pptfaq.com/index.html#name_For_VBeginners
http://skp.mvps.org/vba.htm
ASKER
Thanks for the help - the loop to insert all of the slides at once was good. Recognizing the text box with the sequence number is an issue but I copied and updated manually - not a big deal. The only other issue I had is that I was hoping the font size used in the original slide's title could be copied to the new slide but it's not.
ASKER
Glenna, I'm sorry - I was working with Chris's solution offline and then came back on and accepted it during the time you were posting your follow up. I have a feeling my best solution would be a combination of yours and Chris's but our timing was off.
Inevitably in any question there are a number of potential solutions where all the implementation details are known, so it can always be worth holding off a little while to get the right solution. That said i'm glad to have been of help.
Chris
Chris
Agree with Chris. :-)
MAke sure you tell them what version of PowerPoint.