Log in

View Full Version : Resetting all slide title placeholders to settings in the master



RandomGerman
06-29-2016, 05:38 AM
Hi there,

we all know that: Sometimes users stretch or move placeholders or shrink the font size or do other things they shouldn't do with them. I would like to create a repair tool for this. On ppt-faqs I found this piece of code:


Sub ReapplyLayouts()
Dim oSl As Slide
For Each oSl In ActivePresentation.Slides
oSl.Layout = oSl.Layout
Next
End Sub

It works fine for size and position, but not for, e.g., font size - and it re-inserts other placeholders back on the slide in case there are some on the master and were deleted on the slide. Not exactly what I was looking for.

I kept on searching in this forum and found something, Paul Hossler has posted years ago and found it very helpful. I modified it a bit, coming closer to my intention:


Sub New1()
Dim oPres As Presentation
Dim oSlide As Slide
Dim oShape As Shape

Dim i As Long

Set oPres = ActivePresentation
For Each oSlide In oPres.Slides
For i = oSlide.Shapes.Count To 1 Step -1
With oSlide.Shapes(i)
If .Type = msoPlaceholder Then
Select Case .PlaceholderFormat.Type
Case ppPlaceholderTitle, ppPlaceholderCenterTitle
.Left = 100
.TextFrame.TextRange.Font.Size = 44
End Select
End If
End With
Next
Next
End Sub

This works fine so far - but: To make the macro work for every presentation, I would like to get away from the concrete numbers (like postion left 100 or font size 44) and get to a solution, resetting all parameters to those of the original placeholder in the master. Following the .Layout = .Layout idea from the first stage, I tried .Left = .Left but it doesn't work, nothing happens. Probably because the code refers to where the object is actually positioned, not to where it is in the master.

It might be not too difficult, but at the moment I ran out of ideas. Thank you for any hints.
RG

John Wilson
06-30-2016, 06:17 AM
If you select all the slides and click the RESET button doesn't that do what you need?

RandomGerman
06-30-2016, 07:16 AM
Not exactly, as it is re-inserting deleted body text placeholders. Let's say: I would like to have control only on the title placeholders.

John Wilson
06-30-2016, 07:52 AM
As long as it's only Titles this should work


Sub softReset() Dim osld As Slide
Dim oshp As Shape
Dim ocust As Shape
For Each osld In ActivePresentation.Slides
If osld.Shapes.HasTitle Then
Set oshp = osld.Shapes.Title
Set ocust = osld.CustomLayout.Shapes.Title
With oshp
.Left = ocust.Left
.Top = ocust.Top
.Height = ocust.Height
.Width = ocust.Width
.TextFrame2.TextRange.Font.Name = ocust.TextFrame2.TextRange.Font.Name
.TextFrame2.TextRange.Font.Size = ocust.TextFrame2.TextRange.Font.Size
'anything else to change goes here
End With
End If
Next osld
End Sub

RandomGerman
06-30-2016, 08:14 AM
Aaah, ".HasTitle",".Title" and ".CustomLayout"! Awesome! Thank you, John!

RandomGerman
09-29-2016, 06:05 AM
It works wonderful. When there are different layouts in the presentation, it refers always to the used layout.

Is it possible to modify the code in a way that it ignores different layouts and handles all title placeholders as they would refer to the first layout?

RandomGerman
10-04-2016, 06:54 AM
To specify my last question a bit more: It does not help to use the "SlideLayout" Menu and choose "Title Only", because I want to keep any content untouched - except the title. I tried something like

Set ocust = osld.CustomLayout(1).Shapes.Title

but it seems to be not possible to work with numbers here.

Thank you for any other ideas.

Stephpierre
11-02-2016, 01:29 AM
Hi, I'm just going to chime in a ask two different question - unfortunately I don't know the answer to your question, so I'm just going to pile some on top!

But would you know how to reset the fill colour of the title text box to that of the master, and the border too? I've been looking around for the Syntax's but haven't had much luck so far...

Thanks.

John Wilson
11-02-2016, 01:29 PM
Not sure I understand but maybe


Sub softReset2()
Dim osld As Slide
Dim oshp As Shape
Dim ocust As Shape
For Each osld In ActivePresentation.Slides
If osld.Shapes.HasTitle Then
Set oshp = osld.Shapes.Title
Set ocust = osld.CustomLayout.Shapes.Title
With oshp
.Fill.ForeColor.RGB = ocust.Fill.ForeColor.RGB
.Line.ForeColor.RGB = ocust.Line.ForeColor.RGB
'anything else to change goes here
End With
End If
Next osld
End Sub

Stephpierre
11-14-2016, 04:54 AM
Hi John, once again you saved me and it works beautifully, thanks a lot.

Currently my code works a charm and looks like this:

Sub AllignToMaster()
Dim osld As slide
Dim oshp As shape
Dim ocust As shape
For Each osld In ActivePresentation.Slides
If osld.Shapes.HasTitle Then
Set oshp = osld.Shapes.Title
Set ocust = osld.customLayout.Shapes.Title
With oshp
.Left = ocust.Left
.Top = ocust.Top
.Height = ocust.Height
.Width = ocust.Width
.TextFrame2.TextRange.Font.Name = ocust.TextFrame2.TextRange.Font.Name
.TextFrame2.TextRange.Font.Size = ocust.TextFrame2.TextRange.Font.Size
.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = ocust.TextFrame2.TextRange.Font.Fill.ForeColor.RGB
.Fill.ForeColor.RGB = ocust.Fill.ForeColor.RGB
.Line.ForeColor.RGB = ocust.Line.ForeColor.RGB


End With
End If
Next osld
MsgBox ("All titles have been adjusted to the master slide format")
End Sub

As an additional function the aim would be to align all the titles in a presentation to the title of the current slide (Font, colour, alignment, etc.) and even update the Master so that when new slides added, they would retain the new formatting.

I guess the most simple way to achieve this would be to add a syntax at the start of the macro that changes the master slide title to that of my selected/current slide and then let the macro run its course. Is that possible? And if not, any ideas on what the best way to approach this would be?

Thanks a lot!