+ Reply to Thread
Results 1 to 6 of 6

How to assign a macro to a button?

  1. #1
    Registered User
    Join Date
    08-14-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    17

    How to assign a macro to a button?

    Friends need your help on this...
    I want to assign a set of code to a button. I have a code written to control the inputs of multiple pivots in one of my tabs. But I want to run this only after I click on a button and not every time I change the filter in the pivot.

    I know how to have a button in the cell but am struggling to really link the code to the button. How to do this?

    Thanks for your help
    Cheers

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: How to assign a macro to a button?

    Right-click the button, choose Assign Macro and pick the macro you want to assign.

  3. #3
    Registered User
    Join Date
    08-14-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: How to assign a macro to a button?

    Thanks buddy for your quick reply.

    The problem that I am facing is how to name the set of code that I have to a macro name. So if I do the right click I dont have any macros to assign to. What I have is the set of codes

    HOw to link the set of code that I have to this button?

  4. #4
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: How to assign a macro to a button?

    What I have is the set of codes
    All VBA code must reside in a "module", which can be one of the following:

    1. Standard module
    2. Worksheet module
    3. Workbook module
    4. Class Module

    If your code isn't in one of the above modules, where is it?

    The problem that I am facing is how to name the set of code that I have to a macro name.
    All macros in a standard module typically look something line this:

    Please Login or Register  to view this content.
    The part in bold red font is the macro name and can be something descriptive, like

    Please Login or Register  to view this content.
    Post your code or workbook in order to get more precise help.

  5. #5
    Registered User
    Join Date
    08-14-2009
    Location
    NY, NY
    MS-Off Ver
    Excel 2007
    Posts
    17

    Re: How to assign a macro to a button?

    Apologize for being a bit cryptic here. Pls find attached the file. The macro is in the Pivot tab and i want to run that code only when i click on the Run Pivot button

    Thanks for your help
    Cheers
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    09-01-2009
    Location
    Mexico
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: How to assign a macro to a button?

    Hi there. The problem is that you're using a form control instead of an activex control. Once you've changed its properties at will (include a name like cmdPivotTable or so) and the caption, you can double click on it while in Designer mode and start writing the code. I made some changes to your file so you can see what it's all about. I hope this helps!
    Attached Files Attached Files

+ 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