+ Reply to Thread
Results 1 to 10 of 10

run macro after name change

  1. #1
    Forum Contributor
    Join Date
    06-20-2007
    Location
    Buckeye, AZ
    MS-Off Ver
    365
    Posts
    298

    Question run macro after name change

    In the attached workbook "Quote Sheets" I recorded a macro to copy information to workbook "Quote review". Only after finishing did it dawn on me that the 1st thing users will do is save "Quote sheets" to a new workbook name. Is there a way to have the macro reflect the new workbook name or is there a command like "previous workbook.
    Thank you,
    Sick
    Here's the code:
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sick stigma; 01-23-2011 at 10:06 PM.

  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: run macro after name change

    The trick is to refer to worksheets and workbooks by variable names that you set at the start of the macro. That way you don't need to know names of things.

    Also, selecting and activating are unnecessary once you have variable names to address commands to directly:
    Please Login or Register  to view this content.
    _________________
    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
    06-20-2007
    Location
    Buckeye, AZ
    MS-Off Ver
    365
    Posts
    298

    Re: run macro after name change

    Jerry,
    Thanks for the improved macro. The new workbook names are random (by customer name). The new workbook name will be cell "C7". Any suggestion?
    Last edited by sick stigma; 01-22-2011 at 07:16 PM.

  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: run macro after name change

    For what? If you're asking something specific try again. I'm not getting it.

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

    Re: run macro after name change

    I see C7 is a cell you copied into the wbReview you opened. Are you wanting to save the wbReview with that name instead of saving it back to its original name?

  6. #6
    Forum Contributor
    Join Date
    06-20-2007
    Location
    Buckeye, AZ
    MS-Off Ver
    365
    Posts
    298

    Re: run macro after name change

    wbQuotes will be saved as C7 before this macro runs. wbQuotes is opened. C6:C10 are changed. wbQuotes is then saved as a new wb (C7.xlsw). Then macro "savetoquotereview" is run. Does that make sense?

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

    Re: run macro after name change

    Where does this macro reside? My macro above presumed it was in the workbook with the data to be copied from, which is why I named the variable wsData. Look at the code.

    I don't know what you mean by .xlsw.

  8. #8
    Forum Contributor
    Join Date
    06-20-2007
    Location
    Buckeye, AZ
    MS-Off Ver
    365
    Posts
    298

    Re: run macro after name change

    JB,
    I finally worked through it. Thank you so much for your help!
    "thisworkbook.activesheet" solved all my problems. Now it's ready to roll out.
    One last question: In the code listed below, "J" represents my name on my computer. Is there something that could replace my name to allow the project to run on anyones computer? i.e. C:\Users\'Allusers" or "Anyuser" or something?
    Please Login or Register  to view this content.
    Thanks again for the great advice!

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

    Re: run macro after name change

    This snippet will return the current logged in username:

    Please Login or Register  to view this content.
    Once you've got the username in a string, slip it into your text string where needed using standard syntax.

  10. #10
    Forum Contributor
    Join Date
    06-20-2007
    Location
    Buckeye, AZ
    MS-Off Ver
    365
    Posts
    298

    Re: run macro after name change

    Beautiful! Thanks again!

+ 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