• Command Button – Assign Macro (Excel 2002)

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Command Button – Assign Macro (Excel 2002)

    Author
    Topic
    #432556

    Hello..
    I’m trying to assign a macro to a command button that I made via the “control box” tool bar… the “button” from the “forms” toolbar asks you to “assign” a macro, however the command button in the control box tool bar only let’s you “view the code”. I tried to copy and paste the macro code to the view code screen and apparently I’m doing something wrong as it doesn’t like what I’ve done. You may ask why I just don’t use the “button” option from the “forms” toolbar… purely for cosmetic reasons… I’d like to change the color of the button and I can’t see a way to do so with the “button” option, but the “command button” let’s me change the color. I’d love to find a solution for both issues… assigning a macro to a “command button” from the control box tool bar AND how to change the color of the “button” from the “forms” tool bar… any answers would be greatly appreciated.
    Thank you!
    LJM

    Viewing 0 reply threads
    Author
    Replies
    • #1015079

      You can call your macro from the procedure created by View Code (or by double-clicking the command button while in design mode). Say that your macro is called DoSomething, and that the command button has the default name CommandButton1. Make the code look like this:

      Private Sub CommandButton1_Click()
      Call DoSomething
      End Sub

      Don’t forget to turn off design mode (the first button on the Control Toolbox toggles design mode on/off), for as long as you’re in design mode, the command button won’t do anything.

      • #1015086

        This works great Hans… thanks for the solution! I’m still curious if it is not possible to change the color for the “button” option in the “forms” tool bar?

        • #1015089

          No, you can only change the text format – font, size, color, style. The color of the button itself is determined by the settings in the Appearance tab of the Display Properties control panel, i.e. it is a Windows setting.

    Viewing 0 reply threads
    Reply To: Command Button – Assign Macro (Excel 2002)

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

    Your information: