Instructor PPTX VBA - Standardize the PPTX Slide Deck "Title" position, font, width and other formatting settings
Dealing with PowerPoint slide deck "Title" Insanity
Here is a script that will:
- loop through each slide you have selected in your presentation
- detects all shapes with TextFrames
- it attempts to characterize them for the probability one is actually the intended title
- it uses font size, frame width, height and proximity to the top of the slide
- sometimes a slides will not have a textFrame with the name "title" or worse...
- will have multiple TextFrames with the name "title" but are not a title but an integral part of your slides presented data, and cannot be moved
- once a probable title has been detected, the script will relocate and apply consistent formatting across all selected slides
Sub positionTitleTxtBoxallslide()Dim oSld As SlideDim oShp As ShapeFor Each oSld In ActiveWindow.Selection.SlideRangeDim x As LongFor x = oSld.Shapes.Count To 1 Step -1Set oShp = oSld.Shapes(x)If oShp.HasTextFrame = True ThenIf oShp.Name Like "Titl*" And _oShp.TextFrame.TextRange.Font.Size >= 28 And _oShp.Width > 800 And _oShp.Height < 200 _ThenDebug.Print "found likely candidate, moving shape"SetTextFrameSettings oShpElseIf oShp.Top < 20 And oShp.Width > 800 And oShp.Height < 200 ThenDebug.Print "found likely candidate without correct title, moving shape"SetTextFrameSettings oShpEnd IfEnd IfEnd IfNext xNext oSldEnd SubSub SetTextFrameSettings(myShp)myShp.Left = 41myShp.Top = 0.02myShp.TextFrame2.VerticalAnchor = msoAnchorTopWith myShp.TextFrame.TextRange.Font.Size = 32.Font.Name = "Arial".ParagraphFormat.Alignment = ppAlignLeftEnd WithEnd Sub
I am not a VBA expert, so if you have better ways to do this, please comment and I may update this example with better coding practices.
Comments
Post a Comment