+ Reply to Thread
Results 1 to 5 of 5

MultiFunction Command Button

  1. #1
    Registered User
    Join Date
    10-20-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    10

    MultiFunction Command Button

    I currently have a command button that will copy and export the active worksheet to a new file with a specific naming convention for saving. However, I want the same button which appears in the new file to be repurposed when that file is opened. Is there a way to make either a new button appear in this instance based on the different file name or to have this one change purpose after having run once?
    Last edited by Tobre; 01-26-2011 at 10:36 AM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: MultiFunction Command Button

    You could build a test into the beginning of the macro that looks at the filename and does something different if the filename is anything other than the original template name.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    01-21-2005
    Location
    Colorado
    MS-Off Ver
    2000,2003,2007
    Posts
    481

    Re: MultiFunction Command Button

    I have done this with command buttons and have the macro code check the caption of the command button to with an if statement to determine which code to run.

    Please Login or Register  to view this content.
    This could be modified to your needs and would not revert back to the origial CommandButton's functionality if you don't rename it in the second if statement.

    I have also used a shape (ie. rectangle) with text as a button and after it was clicked the last few lines of the code would delete the original rectangle then add a new rectangle, the text I want it to contain and assign it's 'OnAction' property to call the desired macro when it is clicked.

    This second method is a little more involved but could also be used for your purposes.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: MultiFunction Command Button

    The wbname test would go along the lines of:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-20-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: MultiFunction Command Button

    Thank you very much. It was such a brilliantly simple solution. Worked great!

+ 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