Consulting

Results 1 to 3 of 3

Thread: VBA to change all shapes to "Do not autofit"

  1. #1
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    2
    Location

    VBA to change all shapes to "Do not autofit"

    Hello,

    First post - first question. I hope someone here can help me. I've got a fairly large PowerPoint document, and would like to change all shapes' Text Options to "Do not autofit". The document contains grouped items and normal (not grouped) shapes. I sort of understand how code works, but am by no means a programmer. In the past, I've been able to modify VBA code I found online to suit my needs. This is what I've done so far, but I get error messages when running the script:


    Sub ActivePresentation_DoNotAutofit()
        Dim oshp As Shape
        Dim osld As Slide
        Dim L As Long
    
    
        For Each osld In ActivePresentation.Slides
        For Each oshp In osld.Shapes
    
    
        If oshp.Type = msoGroup Then
            For L = oshp.GroupItems.Count To 1 Step -1
                Call DoNotAutofit(oshp.GroupItems(L))
            Next L
        Else
        Call DoNotAutofit(oshp)
        End If
        Next oshp
        Next osld
    End Sub
    
    
    Sub DoNotAutofit(oshp As Shape)
       oshp.TextFrame2.Autosize = msoAutoSizeNone
    End Sub
    There's probably more elegant solutions for this, for example to implement to 2nd part into the main script. But like this, I can easily modify the script for other things. (And it makes things more simple when I look at the code again in a few months).
    Can someone please help me?

    Many thanks!
    Peter

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,093
    Location
    Your code will error if it hits a shape that does not have a textframe.

    Try:

    Sub DoNotAutofit(oshp As Shape)
    If oshp.HasTextFrame Then
    oshp.TextFrame2.AutoSize = msoAutoSizeNone
    End If
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Newbie
    Joined
    Apr 2019
    Posts
    2
    Location
    This works great.
    Thanks very much, John!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •