PDA

View Full Version : Command Buttons (ActiveX Controls) in Collections & Arrays



j16n
04-12-2017, 11:57 PM
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!

John Wilson
04-13-2017, 03:10 AM
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

j16n
04-13-2017, 09:47 PM
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.

John Wilson
04-13-2017, 11:57 PM
I was originally using it and then didn't delete the declaration later!