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
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