Guest User

Untitled

a guest
Jun 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. Option Explicit
  2.  
  3. Public WithEvents cMDButtonGroup As CommandButton
  4.  
  5. Private Sub cMDButtonGroup_Click()
  6. With cMDButtonGroup
  7.  
  8. If .Caption = "Press" Then
  9.  
  10. ' Add some other button properties
  11.  
  12. Else
  13.  
  14. .Caption = " Complete"
  15.  
  16.  
  17. End If
  18. End With
  19.  
  20. Option Explicit
  21. Dim Buttons() As New cMDButtonClass
  22.  
  23. Sub Buttons()
  24. Dim ButtonCount As Integer
  25. Dim ctl As Control
  26.  
  27. ' Create the Button objects
  28. ButtonCount = 0
  29. For Each ctl In ActiveDocument.Controls ' This may be wrong
  30. If TypeName(ctl) = "CommandButton" Then
  31.  
  32. ButtonCount = ButtonCount + 1
  33. ReDim Preserve Buttons(1 To ButtonCount)
  34. Set Buttons(ButtonCount).ButtonGroup = ctl
  35. End If
  36. End If
  37. Next ctl
  38.  
  39. End Sub
  40.  
  41. Private Sub Document_Open()
  42.  
  43. Call SetupButtons
  44.  
  45.  
  46. End Sub
  47.  
  48. Public WithEvents oBtn As CommandButton
  49.  
  50. Private Sub oBtn_Click()
  51. MsgBox "clicked: " & oBtn.Caption
  52. End Sub
  53.  
  54. Dim colButtons As New Collection '< simpler to manage than an array
  55.  
  56. Sub SetupButtons()
  57. Dim ButtonCount As Integer
  58. Dim ctl, c
  59. Dim oB As cMDButtonClass
  60.  
  61. 'Following Cindy's comment...
  62. For Each ctl In ActiveDocument.InlineShapes
  63. If Not ctl.OLEFormat Is Nothing Then
  64. Set c = ctl.OLEFormat.Object
  65. If TypeName(c) = "CommandButton" Then
  66. Set oB = New cMDButtonClass
  67. Set oB.oBtn = c
  68. colButtons.Add oB
  69. End If
  70. End If
  71. Next ctl
  72.  
  73. End Sub
Advertisement
Add Comment
Please, Sign In to add comment