Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Sub ExecuteAllButtonsContainingX()
- Dim Btn As Button
- Dim Btn_count As Integer
- Btn_count = 1
- For Each Btn In Application.Workbooks.ActiveSheet.Buttons
- Btn(Btn_count).Select
- If ***[The selected button contains Macro X]*** Then
- ***[Call the macro that is assigned to the selected button as if the button was clicked on]***
- Else
- End If
- Btn_count = Btn_count + 1
- Next Btn
- End Sub
- Sub ExecuteAllButtonsContainingX()
- Dim Btn As Button
- 'Counter is redundant if you use [For Each] loop.
- 'Dim Btn_count As Integer
- '-------------------------------------------------
- 'Btn_count = 1
- For Each Btn In ActiveSheet.Buttons
- 'Btn(Btn_count).Select '<--- This is redundant. You don't have to
- ' select button to check its properties.
- 'If property [OnAction] of the current button is not empty
- 'it means there is some macro assigned to this button.
- If Len(Btn.OnAction) Then
- 'This action is called only if there is some macro
- 'assigned to the current button.
- Call Application.Run(Btn.OnAction)
- End If
- 'Btn_count = Btn_count + 1
- Next Btn
- End Sub
- Sub ExecuteAllButtonsContainingX()
- Dim Btn As Button
- For Each Btn In ActiveSheet.Buttons
- If Btn.OnAction = "insertMacroNameHere" Then
- Run Btn.OnAction
- End If
- Next Btn
- End Sub
- Sub ExecuteAllButtonsContainingX(macroName As String)
- Dim Btn As Button
- For Each Btn In ActiveSheet.Buttons
- If Btn.OnAction = macroName Then
- Run Btn.OnAction
- End If
- Next Btn
- End Sub
- Sub ExecuteAllButtonsContainingX()
- Dim Btn As Shape
- For Each Btn In Sheet1.Shapes
- If Btn.FormControlType = xlButtonControl Then
- Run Btn.OnAction
- End If
- Next Btn
- End Sub
- Sub foomsg(Optional vButton As Variant)
- Dim btn As Button
- If IsMissing(vButton) Then
- Set btn = ActiveSheet.Buttons(Application.Caller)
- Else
- Set btn = vButton
- End If
- MsgBox btn.Name
- End Sub
- Sub foo()
- Dim btn As Button
- Dim sMacroName As String
- Dim cf As ControlFormat
- sMacroName = "foomsg"
- For Each btn In ActiveSheet.Buttons
- If Right$(btn.OnAction, Len(sMacroName)) = sMacroName Then
- Run btn.OnAction, btn
- End If
- Next btn
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement