Solved

How do I write VBA to copy a slide's title to a new slide?

Posted on 2008-10-21
8
1,272 Views
Last Modified: 2008-10-22
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.SlideIndex + 1, _
                                       ppLayoutTitleOnly).SlideIndex
     Set oView = Nothing
End With
End Sub
0
Comment
Question by:jolodali
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 21

Expert Comment

by:GlennaShaw
ID: 22771031
You get the fastest answer for this one here: http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.powerpoint&lang=en&cr=US
MAke sure you tell them what version of PowerPoint.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22773808
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
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

Open in new window

0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 22774639
As an example in the art of the possible the following snippet duplicates a named text box on each sheet with the 'a' affix.

You would replace Const boxName = "Fred" with your box name.

Chris


Sub insertSlides()
Dim sld As Slide
Dim sldNum As Integer
Dim newbie As Slide
Const boxName = "Fred"
 
    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
            newbie.Shapes.AddTextbox Orientation:=sld.Shapes(boxName).TextFrame.Orientation, _
                Left:=sld.Shapes(boxName).Left, _
                Top:=sld.Shapes(boxName).Top, _
                Width:=sld.Shapes(boxName).Width, _
                Height:=sld.Shapes(boxName).Height
            newbie.Shapes(newbie.Shapes.Count).Name = boxName
            newbie.Shapes(boxName).TextFrame.TextRange = sld.Shapes(boxName).TextFrame.TextRange & "a"
'            Debug.Print sld.Shapes.Title.TextFrame.TextRange
        Next
    End With
    
End Sub

Open in new window

0
[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 
LVL 21

Expert Comment

by:GlennaShaw
ID: 22775326
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
0
 

Author Comment

by:jolodali
ID: 22775462
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.  
0
 

Author Comment

by:jolodali
ID: 22775499
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.  
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 22775628
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
0
 
LVL 21

Expert Comment

by:GlennaShaw
ID: 22775794
Agree with Chris.  :-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most folk recognise that Microsoft Excel, being a numbers-and-formulae-centric application attracts programmers due to the natural fit in mindset. Conversly, when opening Microsoft's dominant presentation creative application, few consider what…
Introduction In all recent versions of PowerPoint it is possible to trigger animations. This means the animation takes place when a certain shape is clicked. This allows you to run animation “on demand” and outwith the normal sequence of mouse cl…
The viewer will learn how to edit animations within the presentation, incorporate sound, and set everything up with timing.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

634 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question