Results 1 to 7 of 7

Thread: [RESOLVED] CommandBar button OnAction - pass parameter

Threaded View

  1. #1

    Thread Starter
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    [RESOLVED] CommandBar button OnAction - pass parameter

    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:
    1. Sub CmdBarTest()
    2.     Dim cbar As CommandBar, cbctl As CommandBarButton, i As Integer
    3.     Set cbar = Application.CommandBars.Add(Name:="Custom Toolbar6", _
    4.         Position:=msoBarFloating, MenuBar:=False, Temporary:=True)
    5.     cbar.Visible = True
    6.     For i = 1 To 6
    7.         With cbar.Controls.Add(Type:=msoControlButton)
    8.             .Style = msoButtonCaption
    9.             .Caption = "test" & i
    10.             .OnAction = "Action1(3)"        'Action1 fires twice when button clicked
    11. '            .OnAction = "Action2"          'Action2 fires once when button clicked
    12.         End With
    13.     Next i
    14. End Sub
    15.  
    16. Sub Action1(i%)
    17.     Debug.Print "Action1 " & i
    18. End Sub
    19.  
    20. Sub Action2()
    21.     Debug.Print "Action2"
    22. End Sub
    Last edited by VBAhack; Mar 8th, 2006 at 07:59 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width