Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. Sub ExecuteAllButtonsContainingX()
  2.  
  3. Dim Btn As Button
  4. Dim Btn_count As Integer
  5.  
  6. Btn_count = 1
  7.  
  8. For Each Btn In Application.Workbooks.ActiveSheet.Buttons
  9. Btn(Btn_count).Select
  10.  
  11. If ***[The selected button contains Macro X]*** Then
  12. ***[Call the macro that is assigned to the selected button as if the button was clicked on]***
  13. Else
  14. End If
  15.  
  16. Btn_count = Btn_count + 1
  17.  
  18. Next Btn
  19.  
  20. End Sub
  21.  
  22. Sub ExecuteAllButtonsContainingX()
  23. Dim Btn As Button
  24. 'Counter is redundant if you use [For Each] loop.
  25. 'Dim Btn_count As Integer
  26. '-------------------------------------------------
  27.  
  28. 'Btn_count = 1
  29.  
  30.  
  31. For Each Btn In ActiveSheet.Buttons
  32.  
  33. 'Btn(Btn_count).Select '<--- This is redundant. You don't have to
  34. ' select button to check its properties.
  35.  
  36.  
  37. 'If property [OnAction] of the current button is not empty
  38. 'it means there is some macro assigned to this button.
  39. If Len(Btn.OnAction) Then
  40.  
  41. 'This action is called only if there is some macro
  42. 'assigned to the current button.
  43. Call Application.Run(Btn.OnAction)
  44.  
  45. End If
  46.  
  47. 'Btn_count = Btn_count + 1
  48.  
  49. Next Btn
  50.  
  51. End Sub
  52.  
  53. Sub ExecuteAllButtonsContainingX()
  54. Dim Btn As Button
  55.  
  56. For Each Btn In ActiveSheet.Buttons
  57.  
  58. If Btn.OnAction = "insertMacroNameHere" Then
  59.  
  60. Run Btn.OnAction
  61.  
  62. End If
  63.  
  64. Next Btn
  65.  
  66. End Sub
  67.  
  68. Sub ExecuteAllButtonsContainingX(macroName As String)
  69. Dim Btn As Button
  70.  
  71. For Each Btn In ActiveSheet.Buttons
  72.  
  73. If Btn.OnAction = macroName Then
  74.  
  75. Run Btn.OnAction
  76.  
  77. End If
  78.  
  79. Next Btn
  80.  
  81. End Sub
  82.  
  83. Sub ExecuteAllButtonsContainingX()
  84.  
  85. Dim Btn As Shape
  86.  
  87. For Each Btn In Sheet1.Shapes
  88. If Btn.FormControlType = xlButtonControl Then
  89. Run Btn.OnAction
  90. End If
  91. Next Btn
  92.  
  93. End Sub
  94.  
  95. Sub foomsg(Optional vButton As Variant)
  96. Dim btn As Button
  97. If IsMissing(vButton) Then
  98. Set btn = ActiveSheet.Buttons(Application.Caller)
  99. Else
  100. Set btn = vButton
  101. End If
  102. MsgBox btn.Name
  103. End Sub
  104.  
  105. Sub foo()
  106. Dim btn As Button
  107. Dim sMacroName As String
  108. Dim cf As ControlFormat
  109.  
  110. sMacroName = "foomsg"
  111. For Each btn In ActiveSheet.Buttons
  112. If Right$(btn.OnAction, Len(sMacroName)) = sMacroName Then
  113. Run btn.OnAction, btn
  114. End If
  115. Next btn
  116. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement