Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Ankeny, Iowa, USA
    Posts
    344
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Command Button - Assign Macro (Excel 2002)

    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Command Button - Assign Macro (Excel 2002)

    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.

  3. #3
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Ankeny, Iowa, USA
    Posts
    344
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Command Button - Assign Macro (Excel 2002)

    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?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Command Button - Assign Macro (Excel 2002)

    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.

  5. #5
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Ankeny, Iowa, USA
    Posts
    344
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Command Button - Assign Macro (Excel 2002)

    Good to know... thanks Hans!
    LJM

Posting Permissions

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