Consulting

Results 1 to 10 of 10

Thread: VBA to clear any shape border on all slides

  1. #1
    VBAX Regular
    Joined
    Jun 2021
    Posts
    17
    Location

    VBA to clear any shape border on all slides

    Hello - i need a simple VBA to clear shape borders on all slides. the one i have below is not really working...i think the shapeborder.clear is not right.

    any ideas the right fix should be? thank you!



    Sub RemoveShapeBorder()


    Dim sld As Slide
    For Each sld In ActivePresentation.Slides
    sld.ShapeBorder.Clear


    Next
    End Sub

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Posts
    7,946
    Location
    Option Explicit
    
    
    Sub ClearBorders()
        Dim oSlide As Slide
        Dim oShape As Shape, oShape2 As Shape
        
        For Each oSlide In ActivePresentation.Slides
            For Each oShape In oSlide.Shapes
                If oShape.Type = msoGroup Then
                    oShape.Line.Weight = 0
    
                    For Each oShape2 In oShape.GroupItems
                        oShape2.Line.Weight = 0
                    Next
                
                Else
                    oShape.Line.Weight = 0
                End If
            Next
        Next
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,013
    Location
    I would use

    Sub ClearBorders()
        Dim oSlide As Slide
        Dim oShape As Shape, oShape2 As Shape
        
        For Each oSlide In ActivePresentation.Slides
            For Each oShape In oSlide.Shapes
                If oShape.Type = msoGroup Then
                    oShape.Line.Visible = False
    
    
                    For Each oShape2 In oShape.GroupItems
                        oShape2.Line.Visible = msoFalse
                    Next
                
                Else
                    oShape.Line.Visible = False
        
                End If
            Next
        Next
    End Sub
    Paul's code should work but can have unexpected results with placeholders
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  4. #4
    VBAX Regular
    Joined
    Jun 2021
    Posts
    17
    Location
    Thank you John.
    I got a run time error - the specified value is out of range. any idea how to fix this??

    thank you!



    Quote Originally Posted by John Wilson View Post
    I would use

    Sub ClearBorders()
        Dim oSlide As Slide
        Dim oShape As Shape, oShape2 As Shape
        
        For Each oSlide In ActivePresentation.Slides
            For Each oShape In oSlide.Shapes
                If oShape.Type = msoGroup Then
                    oShape.Line.Visible = False
    
    
                    For Each oShape2 In oShape.GroupItems
                        oShape2.Line.Visible = msoFalse
                    Next
                
                Else
                    oShape.Line.Visible = False
        
                End If
            Next
        Next
    End Sub
    Paul's code should work but can have unexpected results with placeholders

  5. #5
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,013
    Location
    Quote Originally Posted by rwc1023 View Post
    Thank you John.
    I got a run time error - the specified value is out of range. any idea how to fix this??

    thank you!
    Most likely reason is you have a shape that cannot have the line set, maybe an ActiveX shape or a Table?

    Try ignoring the error like this

    Sub ClearBorders()    
    Dim oSlide As Slide
        Dim oShape As Shape, oShape2 As Shape
        On Error Resume Next
        For Each oSlide In ActivePresentation.Slides
            For Each oShape In oSlide.Shapes
                If oShape.Type = msoGroup Then
                    oShape.Line.Visible = False
    
    
                    For Each oShape2 In oShape.GroupItems
                        oShape2.Line.Visible = msoFalse
                    Next
                Else
                    oShape.Line.Visible = False
                End If
            Next
        Next
    End Sub
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Posts
    7,946
    Location
    John --

    1. I added On Error to handle Tables and such

    2. Went with .Visible = msoFalse

    3. Add recursion in case a Group contained other Groups

    4. But .Visible = msoFalse seems to change Title placeholders to top left
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,013
    Location
    Not sure why Paul (yet) but it doesn't happen if I recreate the title slide OR reapply the Title layout to the first slide.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Posts
    7,946
    Location
    More PP wierdness ??

    The Before and After (including the PPTM After)

    But didn't do it to Slide 2

    Before.JPG


    After.JPG
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  9. #9
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,013
    Location
    Quote Originally Posted by Paul_Hossler View Post
    More PP wierdness ??

    The Before and After (including the PPTM After)

    But didn't do it to Slide 2


    Before.JPG


    After.JPG
    Very strange. Even looking through the XML I can see nothing strange about the slide that misbehaves.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  10. #10
    VBAX Sage
    Joined
    Apr 2007
    Posts
    7,946
    Location
    Slide 3 Title does the same thing, but Slide 2 doesn't


    I didn't see any common thread
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

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