Creating Macros

how to create macro to set text box margin for all ppt file
Amitesh SinhaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jamie GarrochSenior Technical Consultant at BrightCarbonCommented:
Try this Amitesh:

Option Explicit

' ===============================================================
' PowerPoint VBA Macro
' Purpose : Set all margins for all text shapes in a presentation
' Author : YOUpresent, http://youpresent.co.uk/
' Answer to ExpertsExchange question 29083118
' ===============================================================
Public Sub SetTextboxMargins()
  Dim oSld As Slide
  Dim oShp As Shape
  Dim oGrpItem As Shape
  
  For Each oSld In ActivePresentation.Slides
    For Each oShp In oSld.Shapes
      If oShp.Type = msoGroup Then
        For Each oGrpItem In oShp.GroupItems
          If oGrpItem.HasTextFrame Then SetMargins oGrpItem
        Next
      Else
        If oShp.HasTextFrame Then SetMargins oShp
      End If
    Next
  Next
End Sub

' ===============================================================
' Supporting function for SetTextboxMargins
' Purpose : Sets all margins for the referenced shape
' Inputs : oShp - PowerPoint shape containing a TextFrame
' Return : True if successful, False if error
' ===============================================================
Private Function SetMargins(oShp As Shape) As Boolean
  On Error Resume Next
  Select Case oShp.Type
    Case msoTextBox, msoAutoShape
      With oShp.TextFrame
        .MarginBottom = 1
        .MarginLeft = 1
        .MarginRight = 1
        .MarginTop = 1
      End With
  End Select
  If Err = 0 Then SetMargins = True
  On Error GoTo 0
End Function

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Amitesh SinhaAuthor Commented:
Jamie Garroch

Thank you and it's very helpful. here would you please allow me to be more specific with my request... can i have a macro that sets internal margin 0.05" for all four side of text box with/without outlined and shaded?

Regards,
Jamie GarrochSenior Technical Consultant at BrightCarbonCommented:
That is possible too Amitesh but it's a different question so please close this one and open a new one. In the new question, please be more specific about the new requirement "with/without outlined and shaded".
Amitesh SinhaAuthor Commented:
Sure Janmie!! Thanks for all your kind support..!!
Amitesh SinhaAuthor Commented:
Thanks Jamie!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft PowerPoint

From novice to tech pro — start learning today.