• Modify Buttons with VBA (XL2000 SR3)

    • This topic has 2 replies, 2 voices, and was last updated 17 years ago.
    Author
    Topic
    #450970

    I can add a toolbar to a workbook and add one or more buttons to the toolbar by going to Customise and dragging the yellow smiley onto the toolbar, using the macro recorder to give me code for these actions. However when I change the style of the button to text and image, alter the button name, alter the button image, or assign a macro to the button, no code appears in the recorded macro. How does one do these things by code?

    Viewing 0 reply threads
    Author
    Replies
    • #1109125

      You need to write such code from scratch. In this case, you need to modify a CommandBarButton object; here is an example:

      Sub ModifyButton()
      Dim ctl As CommandBarButton
      Set ctl = CommandBars("Standard").Controls("F2V")
      With ctl
      .Style = msoButtonIconAndCaption
      .Caption = "Formulas to Values"
      .FaceId = 37
      .OnAction = "MyMacro"
      End With
      End Sub

      Click in a word such as Style or FaceId in the Visual Basic Editor and press F1 to get help.

    Viewing 0 reply threads
    Reply To: Modify Buttons with VBA (XL2000 SR3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: