+ Reply to Thread
Results 1 to 7 of 7

Change code to automatically SAVE when workbook is opened

  1. #1
    Registered User
    Join Date
    06-08-2009
    Location
    Annapolis, Maryland
    MS-Off Ver
    Excel 2007
    Posts
    85

    Change code to automatically SAVE when workbook is opened

    Hello all! I have a button that when clicked runs a macro that saves the workbook in a specific location --

    Please Login or Register  to view this content.
    Is there a way this macro can run as soon as the workbook opens? I would need the code to run as it is above -- so that it saves the workbook in the same location called out above.

    Thanks for your help.

  2. #2
    Valued Forum Contributor
    Join Date
    03-23-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    1,093

    Re: Change code to automatically SAVE when workbook is opened

    Hello,

    Under this workbook, there is an OnOpen Event.

  3. #3
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Change code to automatically SAVE when workbook is opened

    try adding this to your ThisWorkbook module

    Please Login or Register  to view this content.
    If you liked my solution, please click on the Star -- to add to my reputation

    If your issue as been resolved, please clearly state so and mark the thread as [SOLVED] using the thread tools just above the first post.

  4. #4
    Registered User
    Join Date
    06-08-2009
    Location
    Annapolis, Maryland
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Change code to automatically SAVE when workbook is opened

    Quote Originally Posted by DGagnon View Post
    try adding this to your ThisWorkbook module

    Please Login or Register  to view this content.

    Thanks for your replies. I pasted your code above and received an error in this line --

    ActiveWorkbook.SaveAs FileName:=stFileName

    Should that line be altered?

  5. #5
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Change code to automatically SAVE when workbook is opened

    Try adding
    Please Login or Register  to view this content.
    just before that line and make sure that the variable is correct.

  6. #6
    Registered User
    Join Date
    06-08-2009
    Location
    Annapolis, Maryland
    MS-Off Ver
    Excel 2007
    Posts
    85

    Re: Change code to automatically SAVE when workbook is opened

    I see where it would work. My problem then becomes: the workbook opens and immediately tries to save to the folder before the file name is added (auto copied from the workbook that called upon it). I'm going to have to play with this some more.

    Thank you again! Your help is greatly appreciated.

  7. #7
    Forum Expert DGagnon's Avatar
    Join Date
    02-23-2012
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003, 2007
    Posts
    1,645

    Re: Change code to automatically SAVE when workbook is opened

    no problem.

+ 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