Consulting

Results 1 to 4 of 4

Thread: Command Buttons (ActiveX Controls) in Collections & Arrays

  1. #1
    VBAX Newbie
    Joined
    Apr 2017
    Posts
    4
    Location

    Command Buttons (ActiveX Controls) in Collections & Arrays

    Hi,

    My question is probably quite simple for those experienced, but I am new to VBA and programming in general. Is it possible to create an Array or Collection of Command Buttons (the ActiveX Control buttons) in PowerPoint, so I can easily manipulate them in group and with less code?

    For instance, if I want to make them all visible or invisible at the same time.


    Thanks!

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Maybe something based on:

    Dim myColl As New Collection
    
    Sub coll()
       Dim oshp As Shape
       Dim osld As Slide
       Dim x As Long
    
    
       For Each osld In ActivePresentation.Slides
          For Each oshp In osld.Shapes
             If oshp.Type = msoOLEControlObject Then
                If oshp.OLEFormat.ProgID = "Forms.CommandButton.1" Then
                   myColl.Add oshp
                End If
             End If
          Next oshp
       Next osld
    
    
    End Sub
    
    
    Sub hide_Show()
       Dim x As Long
       For x = 1 To myColl.Count
          myColl(x).Visible = Not myColl(x).Visible
       Next x
    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 2017
    Posts
    4
    Location
    Thanks John this is great! not only answered my question but also helped me figure out other issues, I was struggling with multiple controls and shapes...

    One question though, any particular reason to declare the x variable in the Sub Coll()? Noticed that it wasn't used there....just out of curiosity.

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    I was originally using it and then didn't delete the declaration later!
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Tags for this Thread

Posting Permissions

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