Is it legal to pass parameter values to the sub triggered by OnAction? I tried it and for some reason the sub associated with OnAction fires twice when clicked whereas the parameterless version only fires once. Why twice?
VB Code:
Sub CmdBarTest() Dim cbar As CommandBar, cbctl As CommandBarButton, i As Integer Set cbar = Application.CommandBars.Add(Name:="Custom Toolbar6", _ Position:=msoBarFloating, MenuBar:=False, Temporary:=True) cbar.Visible = True For i = 1 To 6 With cbar.Controls.Add(Type:=msoControlButton) .Style = msoButtonCaption .Caption = "test" & i .OnAction = "Action1(3)" 'Action1 fires twice when button clicked ' .OnAction = "Action2" 'Action2 fires once when button clicked End With Next i End Sub Sub Action1(i%) Debug.Print "Action1 " & i End Sub Sub Action2() Debug.Print "Action2" End Sub





Reply With Quote