Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code to Change PowerPoint Slide Title 1

Status
Not open for further replies.

CCHall

IS-IT--Management
May 3, 2005
46
US
I want to be able to change slide titles on an existing presentation I was given. The slides change every week, and there are title pages that have hyperlinks to the slides. Without slide titles, I have to go in and manually change the links every week, and there are several dozen of them. I believe if I had slide titles, that would help immensely, but a slide title box was not used in creating any of the slides. Any help would be greatly appreciated.
 
The code to change slide titles:
Code:
Dim ppSlide As PowerPoint.Slide
With Application.Presentations(1)
    For Each ppSlide In .Slides
        If ppSlide.Shapes.HasTitle Then ppSlide.Shapes.Title.TextFrame.TextRange = "New title"
    Next ppSlide
End With

However you may need to work with hyperlinks, thread708-969041 may be helpful.

combo
 
But these are NOT titles, correct? They are ordinary textboxes, that happen to contain text considered as titles, right?

Gerry
 
Right, the slides do not currently have titles. I need some way of giving each slide its own individual title. Thanks very much!
 
Depending on available data and needs, more or less complicated macro can be used.
This code converts (copies) text box selected into missing slide title frame:
Code:
Dim shSource As PowerPoint.Shape, shTarget As PowerPoint.Shape
If ActiveWindow.Selection.ShapeRange.Parent.Shapes.HasTitle = False Then
    Set shSource = ActiveWindow.Selection.ShapeRange(1)
    Set shTarget = shSource.Parent.Shapes.AddTitle
    shTarget.TextFrame.TextRange.Text = shSource.TextFrame.TextRange.Text
    shSource.PickUp
    With shTarget
        .Apply
        .Left = shSource.Left
        .Width = shSource.Width
        .Top = shSource.Top
        .Height = shSource.Height
    End With
    shSource.Delete
End If

combo
 
Thanks for the code! Unfortunately, I get an error message - "Shapes.AddTitle: Invalid Request. This slide layout does not permit a title." Does this mean that I won't be able to add a title to any of these pages?

Thanks again for the help!
 
AddTitle method works for slides with deleted title template. It fails for slide layouts that do not provide title: blank or largeobject.
In that case change of layout is required (dim ppSlide as Slide):
Code:
Set ppSlide=shSource.Parent
if ppSlide.Layout=ppLayoutBlank Then ppSlide.Layout=ppLayoutTitleOnly
You have to test for Layout=ppLayoutLargeObject too.

After the change of layout, title template is added. It is usually blank, but can contain text if previous (blank) layout was converted from a slide with title.

You need to take all this into account before applying above code. Title shape should be deleted if empty or left if already contains a title.

In practice you could, taking the above code is a starting point and using powerpoint vba help:
- test for layout, if necessary, change to containing title,
- select shape you want to convert to title, and:
- do nothing if slide has no empty title,
- create a title shape if there is no title,
- copy shape's contents and formatting to title and delete source shape.

For future work, the presentation's author could change the presentation layout. In general, you will not be able to fully automate the work as long as there are no clear condition to recognise shape to be converted to title.

combo
 
I appreciate the help. In the end, it was easier to change the slide layout on each slide individually, but this advice will be very helpful for the future. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top