+ Reply to Thread
Results 1 to 12 of 12

Command color change upon a click

  1. #1
    Registered User
    Join Date
    09-28-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    65

    Command color change upon a click

    Hi

    I am struggling to find code that will change the command box color once it's pressed, either background color of the command button or text color of the command button. Both would be fabulous...:-D

    I have the below code I got while googling but it does not work though. I already have a macro for copying data from other excel...I just want to amend this code to existing macro.

    Please Login or Register  to view this content.


    I would really appreciate if anyone can help with the right code.

    Thanks in advance.

    Su.
    Last edited by Cutter; 10-17-2012 at 09:15 PM. Reason: Added code tags

  2. #2
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Command color change upon a click

    Here is an example of how command button color
    properties can be changed in the button's click event.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-28-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    65

    Re: Command color change upon a click

    Hi xLJer,

    Thanks for your kind reply.

    I tried with below as I am using a Button from form tool bar and it says 'invalid use of Me keyword.'

    If Take out e keyword it throws Object Required. I am very to new to macro so struggling to understand the silly errors...:-P. Please advice what I am missing here.

    Please Login or Register  to view this content.
    Last edited by Cutter; 10-18-2012 at 10:35 AM. Reason: Added code tags

  4. #4
    Registered User
    Join Date
    09-25-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Command color change upon a click

    hi there i have tried xLJer's code in a workbook of mine with acommand button and it seems to work fine.

    on the module do you have this present
    Please Login or Register  to view this content.
    Also check that the Button you want to change colour is called CommandButton1. To do this on the form click the button and check it's properties.

    If it is called something different then change the replace all the "CommandButton1"'s in the code to whatver you have called the command button. or just change the name of the command button to Command Button 1

    Hope this helps.

  5. #5
    Registered User
    Join Date
    09-28-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    65

    Re: Command color change upon a click

    Hi Jayruss

    Thanks for the reply.

    I have attached an excel with what I am doing.

    Sheet1, I have inserted the command button from control toolbox toolbar. I am using the code same as xLJer has given. It does not do anything when I double click the commandbutton it just opens the code.

    Sheet2, I have added the Button from Forms Toolbar. I have edited the code to match the label name and macro name and assigned the Test_Color_Change macro to the code. It gives me 'Expected Function or Variable' error.

    I appreciate your time and patience...:-)

    Thanks,
    Su.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-25-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Command color change upon a click

    Should work Now, i used an Activex button instead of and actual form button and now all works. just to let you know i am new to VBA aswell therefore my workaround may not be the most elegant. however it does work attacthed is the updated worksheet.
    Attached Files Attached Files

  7. #7
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Command color change upon a click

    @ macrofan2012

    Welcome to the forum.

    Please notice that [CODE] tags have been added to your post(s). The forum rules require them so please keep that in mind and add them yourself whenever showing code in any of your future posts. To see instructions for applying them, click on the Forum Rules button at the top of the page and read Rule #3.
    Thanks.

  8. #8
    Registered User
    Join Date
    09-28-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    65

    Re: Command color change upon a click

    That works but I can't really use it for my purpose unless I know how does the code works for a form toolbar command box as I am using excel 2003. Sorry.

    I have a long code for other formulas etc, everything works perect. All I need is to incorporate the color change code in the same macro and I am all done.

    Anyone can help me on this please. Would be great if someone can explain how doe this work for forms toolbar.

    Thanks for having a look anyways..:-)
    Su.

  9. #9
    Registered User
    Join Date
    09-25-2012
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Command color change upon a click

    Unfortunatley you cannot change the colour of a standard form button.

    One workaround would be to insert a line of code into your existing code that changes the colour of a cell next to the button to determine wether the code has been run or not ?

    Furthermore i ran a compatibility check on the Workbook i gave you and no compatabililty issues came about, so you should be able to use the code that i gave to you and within that same module of "CommandButton1_(Click)" just copy the rest of the code you have already written into said module and all should run fine (fingers crossed)

  10. #10
    Registered User
    Join Date
    09-28-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    65

    Re: Command color change upon a click

    I do not know how to assign this code to a commandbutton.

    I was just googling this and nothing helps me out.

    I right clicked the command button and selected view code where I had pasted this code. To assign the code I right clicked again and selected property and then closed the code and property. But after that when I click command button it only opens the code and nothing happens unfortunately.

    This is really annoying. Why excel can't be simple and easy. I like using forms button it atleast says to assign macros. Excel has some features with some not others. Everytime you struggle for silly things.

    Anyone can help resolving this issue please.

  11. #11
    Forum Contributor
    Join Date
    07-27-2012
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    198

    Re: Command color change upon a click

    When you use the command button to run code, you should not double click on it.
    You say that it just opens up the code when you double click. That means you are
    in design mode (where you can edit code and change control properties).

    On the VBA toolbar there is an icon with a triangle and ruler symbol. This symbol may
    appear selected by having a border surrounding it; if it does not have a border, click on it
    to select it.
    Single click on the command button, for purposes of your learning, and you will see small
    round symbols surrounding the button. Click on the triangle/ruler icon and watch the
    symbols surrounding the button disappear, which means you have gone out of design mode
    and can now use the button with a single click to run code assigned to its click event.
    Last edited by xLJer; 10-18-2012 at 12:15 PM.

  12. #12
    Registered User
    Join Date
    09-28-2012
    Location
    UK
    MS-Off Ver
    Excel 2003
    Posts
    65

    Re: Command color change upon a click

    Thank you very much xLJer for the explanation. it solved my problem....hurrrah.

    I really appreciate....muah..:-)

    Thanks,
    Su.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1