+ Reply to Thread
Results 1 to 5 of 5

Use Macro To Change Macro Assigned To Command Button

  1. #1
    Registered User
    Join Date
    03-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    37

    Use Macro To Change Macro Assigned To Command Button

    My worksheet has 42 different command buttons with macros assigned to them. I need to change the macro assigned to those command buttons using another, separate macro. I know how to change the assigned macro if I were using just buttons (macro recorder showed me), but I don't know how to change the assigned macro when we're talking about command buttons. If this is not feasible, a find / replace would work on the existing macro that is already assigned to the buttons, but actually changing the macro assigned in preferred. The command button is on the sheet itself, not in a UserForm or otherwise. Any help would be appreciated.

    Thanks,

    CVinje

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Use Macro To Change Macro Assigned To Command Button

    Hi CVinje
    depends but something like
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    sub are call testthree and testtwo
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Use Macro To Change Macro Assigned To Command Button

    Scratch this message, the macros weren't tested properly. See message later on.
    Last edited by foxguy; 05-25-2010 at 07:25 PM.
    Foxguy

    Remember to mark your questions [Solved] and rate the answer(s)
    Forum Rules are Here

  4. #4
    Registered User
    Join Date
    03-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    37

    Re: Use Macro To Change Macro Assigned To Command Button

    Not really sure what to do with the provided macros - I seem to lack the knowledge to implement them accordingly. The first part of the first macro posted does create a new button; however it stops with error "Run-time error '1004' ; Unable to set the OnAction property of the Button class. The other issue is that the easiest solution would be to simply reassign the macro already associated with the Command Button on the page instead of creating new buttons. The problem I'm running into is that the existing buttons are Command Buttons (which is desired for formatting options, etc). It looks as though I may have to give up on retaining the format of Command Button and go with a simple button to accomplish this; however, I just can't believe that there is no straight forward answer for how to accomplish what I need via a macro (I can believe that I'm not educated enough to solve the problem my self, or ask the question properly the help others help me ).

    I really appreciate your reply and apologize for my late response; however, I did not foresee being away from a computer for such an extended period of time. Any further help would be greatly appreciated.

    CVinje

  5. #5
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: Use Macro To Change Macro Assigned To Command Button

    CVinje;

    Quote Originally Posted by CVinje View Post
    Not really sure what to do with the provided macros
    I'm sorry, I tried simplifying my macros, but I did it here in Excel Forum without testing them. I just assumed they would work like they do in my workbooks. They don't, so here they are after testing.

    I'm assuming that you don't know how to modify your menus. If that's wrong, I apologize.

    1. Copy all these subs/functions into a Standard Module.

    2. Run "Create_MenuButton_For_Button_OnAction()". It will put a temporary button on your Menu Bar with the Caption "Set_Button_OnAction". The button will be removed when you close Excel.

    3. Select a button with your right mouse button. This will put a shadow around the button.

    4. While the button is selected, click "Set_Button_OnAction" on your menu. This will assign a macro "Button_Clicked()" to the button.

    5. Click the button (you'll have to move your cursor to another cell 1st). This will stop inside "Button_Clicked()" where you can tell VBA where you want the button to go.

    6. Create a "Case <button caption>" and your real sub() name inside "Button_Clicked()"

    7. Go back and click the button again and it should go to the sub you want to assign.

    8. Do steps 3 - 7 with another button.

    When you create a new button, assign the macro "Button_Clicked()" to it, and put the real sub() inside Button_Clicked(), and you can then change it anytime you want without having to modify the button itself. You can use my "Create_Button()" macro to do that with just one mouse click.

    Please Login or Register  to view this content.
    Last edited by foxguy; 05-25-2010 at 07:35 PM.

+ 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