PDA

View Full Version : [SOLVED:] Referring subtitle of a slide in order to format using VBA PowerPoint



CuriosityBug
09-06-2019, 08:00 AM
Hello all,

I am trying to set the position and formatting of title, subtitle in the slide. I tried doing it using the following code. It works on title but not on subtitle. How can we get reference of subtitle to work on its position, font size etc.


Sub Titles()
Dim osld As Slide, oshp As Shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.Type = msoPlaceholder Then

If oshp.PlaceholderFormat.Type = ppPlaceholderTitle Then
With oshp
.Top = 5
.Left = 5
.TextFrame.TextRange.Font.Name = "Times New Roman"
.TextFrame.TextRange.Font.Size = 24
End With

ElseIf oshp.PlaceholderFormat.Type = ppPlaceholderSubtitle Then
With oshp
.Top = 10
.Left = 10
.TextFrame.TextRange.Font.Name = "Times New Roman"
.TextFrame.TextRange.Font.Size = 18
End With

End If


End If

Next oshp
Next osld
End Sub

Paul_Hossler
09-06-2019, 09:39 AM
Not every slide has a Subtitle placeholder, even if it looks like a subtitle

1. Is that a true placeholder type Subtitle, or a text box that you're using as a subtitle

2. Could you use the Master Slide(s) to format the way you want?

3. Little rearranging and one add



Option Explicit

Sub Titles()
Dim oSld As Slide, oShp As Shape

For Each oSld In ActivePresentation.Slides
For Each oShp In oSld.Shapes
With oShp
If .Type = msoPlaceholder Then
Select Case .PlaceholderFormat.Type
Case ppPlaceholderTitle, ppPlaceholderCenterTitle ' <<<<<<<<<<<<<<
.Top = 5
.Left = 5
.TextFrame.TextRange.Font.Name = "Times New Roman"
.TextFrame.TextRange.Font.Size = 24

Case ppPlaceholderSubtitle
.Top = 10
.Left = 10
.TextFrame.TextRange.Font.Name = "Times New Roman"
.TextFrame.TextRange.Font.Size = 18
End Select
End If
End With
Next oShp
Next oSld
End Sub

CuriosityBug
09-06-2019, 10:18 AM
I am working on already formatted presentation( not creating it from scratch). Could you please guide me on how to find whether it is "placeholder type Subtitle, or a text box". When I tried to detect this using "selection pane" to see type it is named as " Text placeholder 1, Text placeholder 2"..in many slides.

In order to use master slide, I am already working on well formatted presentation and moreover first slide doesn't have style as showed in attached picture.

CuriosityBug
09-06-2019, 10:19 AM
The code you suggested earlier is behaving same like the one I shared. Only "Title" is altered.

John Wilson
09-07-2019, 06:47 AM
If the Name of the placeholder is "Text placeholder xx" then they are almost certainly NOT SubTitle placeholders but Text Placeholders, In fact except for the Title Slide Layout you will hardly ever see SubTitle Placeholders because they are hard to add!

John Wilson
09-08-2019, 08:25 AM
Why not just reset the Custom Layout?

Paul_Hossler
09-08-2019, 01:28 PM
The code you suggested earlier is behaving same like the one I shared. Only "Title" is altered.

I expected that since the Textbox that looks like a subtitle for the slide is not a true Subtitle Placeholder

Is there some property common to all such "subtitle" Textboxes that the macro could check for?

Attach a small presentation with a couple of slides (remove sensitive data) and indicate which Textboxes that you want to apply a format macro to

Even if it is an existing presentation, you can still use Masters to control the formatting

CuriosityBug
09-09-2019, 04:03 AM
Hello John,
Yes, I guess they are no more "SubTitle placeholders". When I check for type of placeholder(ppPlaceholderType) it is returning a value 1 for both "Title" and "Subtitle".

Paul_Hossler
09-09-2019, 06:04 AM
See if you can use this

http://www.pptfaq.com/FAQ00769_Creating_-Pseudo-Subtitles-.htm

John Wilson
09-09-2019, 06:08 AM
That would be very strange

Type 1 is Title but only one of this type is allowed on a layout. What was your exact code?

CuriosityBug
09-09-2019, 06:27 AM
Hello Paul,

The common element I found is the name in each slide as " text place holder xx". I am not sure about it. Attaching the demo ppt with slides which has two text boxes I want to apply macro. :)

CuriosityBug
09-09-2019, 06:28 AM
John, I attached ppt that could provide clear insight:)

John Wilson
09-09-2019, 07:06 AM
What you have is a slide with a blank layout. Someone has copy pasted placeholders from the master but this doesn't work so the two shapes are not placeholders at all just normal textboxes. You are going to have a hard time fixing this because it's a mess.

CuriosityBug
09-09-2019, 07:21 AM
Thanks for the link Paul. This helped me to get awareness. To position Left and Top, make everything automated this cannot be used I guess.

CuriosityBug
09-09-2019, 07:28 AM
What you have is a slide with a blank layout. Someone has copy pasted placeholders from the master but this doesn't work so the two shapes are not placeholders at all just normal textboxes. You are going to have a hard time fixing this because it's a mess.

I removed the other components in slides like table,text boxes for confidentiality. But, the format of title and subtitle is same as shown. My bad to hear this. Thanks for the insight John. At least this taught me something:)