+ Reply to Thread
Results 1 to 6 of 6

Macro to close workbook and replace with new workbook

  1. #1
    Registered User
    Join Date
    10-22-2009
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2003
    Posts
    32

    Macro to close workbook and replace with new workbook

    Hi,

    Is it possible to create a macro to close the currently open workbook, delete the file, then replace that file with another workbook stored on the share drive. Then finally open the workbook? I basically want to put a command button the user clicks and will replace their workbook with a new version stored on the network drive.

    Does anybody have a sample code that can accomplish the above request?

    Thanks

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,369

    Re: Macro to close workbook and replace with new workbook

    Hi chinaboy,

    Your question is a little strange. You will need the Excel Macro running behind a workbook. If you close that workbook then the macro will no longer run. When you ask about the "currently open workbook" you must have two workbooks open. One of them has the macro running in it and the other one is what you want closed, I guess. Can you rethink this problem and give a better description based on my answer above?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    10-22-2009
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: Macro to close workbook and replace with new workbook

    Your correct, the question is a bit strange, but I thought I would give it a try. In access I was able to do something similar.

    1. When the client opens their front-end, the code checks to see if the front-end is the latest version.

    2. If the version numbers are different, then it will give the user a message saying that their front-end is out of date and it will now close and then reopen. It closes and then deletes the old database, copies the new front-end from the location set in the location table, and then reopens the front-end for the user.


    I was hoping to find a solution like this in excel. Should I just give that up and find another solution?

  4. #4
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: Macro to close workbook and replace with new workbook

    Sounds possible, but would take a bit of time to check variables in another workbook, saveas, etc, but the basic idea is;

    Open your sample workbook, check source version (I'm assuming buried in your template/main workbook), if different version than source then execute some macro in the default named workbook, grab the activeworkbook's name, close it, save template workbook as activeworkbook's name.

  5. #5
    Registered User
    Join Date
    10-22-2009
    Location
    Raleigh, NC
    MS-Off Ver
    Excel 2003
    Posts
    32

    Re: Macro to close workbook and replace with new workbook

    Thank you for the responses. I already have a procedure that compares the open workbook with a text file that has the updated version number. Can I have a command button that the user clicks then runs a batch file that can close the workbook and copy and open the updated workbook?

  6. #6
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: Macro to close workbook and replace with new workbook

    I can't see why it wouldn't be possible to run a batch file, although you'd probably need some references added under your vba editor to execute it and my expertise in that area is limited. If your batch file is just to used to execute closing the current workbook and opening the updated workbook - I would imagine it would be easier to just keep it all in Excel.

+ 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