Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- Public WithEvents cMDButtonGroup As CommandButton
- Private Sub cMDButtonGroup_Click()
- With cMDButtonGroup
- If .Caption = "Press" Then
- ' Add some other button properties
- Else
- .Caption = " Complete"
- End If
- End With
- Option Explicit
- Dim Buttons() As New cMDButtonClass
- Sub Buttons()
- Dim ButtonCount As Integer
- Dim ctl As Control
- ' Create the Button objects
- ButtonCount = 0
- For Each ctl In ActiveDocument.Controls ' This may be wrong
- If TypeName(ctl) = "CommandButton" Then
- ButtonCount = ButtonCount + 1
- ReDim Preserve Buttons(1 To ButtonCount)
- Set Buttons(ButtonCount).ButtonGroup = ctl
- End If
- End If
- Next ctl
- End Sub
- Private Sub Document_Open()
- Call SetupButtons
- End Sub
- Public WithEvents oBtn As CommandButton
- Private Sub oBtn_Click()
- MsgBox "clicked: " & oBtn.Caption
- End Sub
- Dim colButtons As New Collection '< simpler to manage than an array
- Sub SetupButtons()
- Dim ButtonCount As Integer
- Dim ctl, c
- Dim oB As cMDButtonClass
- 'Following Cindy's comment...
- For Each ctl In ActiveDocument.InlineShapes
- If Not ctl.OLEFormat Is Nothing Then
- Set c = ctl.OLEFormat.Object
- If TypeName(c) = "CommandButton" Then
- Set oB = New cMDButtonClass
- Set oB.oBtn = c
- colButtons.Add oB
- End If
- End If
- Next ctl
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment