+ Reply to Thread
Results 1 to 2 of 2

"file opener" - code to open another workbook, save as, and close both original files

  1. #1
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    "file opener" - code to open another workbook, save as, and close both original files

    I'm probably overthinking this, but what I'm looking for is:

    I need VBA code to put in the Workbook_Open() event of a blank workbook, which I will call "File Opener.xlsm".

    When File Opener.xlsm is opened, I need it to do the following:

    1. open another workbook stored on a network drive - "networkfilepath\Master Log.xlsm".
    2. save a copy of Master Log.xlsm in a specified folder on the desktop of the local machine, adding a time/date stamp to the file name - "pathoflocalfolder\Master Log4-10-19-1322.xlsm", assuming the file was opened today at 1:22 pm.
    3. close the original network copy of Master Log.xlsm without saving any changes (none should have been made, and I believe "SaveAs" will automatically close this file already)
    4. open the newly saved and timestamped file, if it's not already open as a result of the SaveAs command (I believe it will be)
    5. close File Opener.xlsm without saving any changes

    Additionally, I don't want any message prompts to pause and ask for user confirmation, such as "save changes before closing", etc.

    Basically, from the user's perspective, clicking the file icon to open "File Opener" from the desktop should feel like directly opening the Master Log file from the network, except the now open file is a locally saved copy and the original file is left closed and unchanged.


    I started writing code that created the new file first, and then opened the network file, copied sheets, inserted them to the new file, deleted excess sheets, and so on, but I kept having issues with maintaining correct formatting of the cells and whatnot, and it just seems there should be an easier way. I was also struggling with the formatting of the time/date stamp, and had just accepted using the numeric value of the "Now" function.

    Any help would be appreciated... I've been debugging other areas of the code on this project for days, and just went live for company-wide BETA testing today, so I'm a bit fried at the moment.

    Thanks in advance!

  2. #2
    Forum Contributor
    Join Date
    10-01-2018
    Location
    Virginia Beach, VA
    MS-Off Ver
    365
    Posts
    129

    Re: "file opener" - code to open another workbook, save as, and close both original files

    Another thought, just in case, would be to either add the seconds to the end of the time/date stamp, or add some error handling code to overwrite the existing file when saving, in the case that someone opens "File Opener" twice in a span of less than 60 seconds. That could potentially try to create a second file with the same time/date stamp, which would be unnecessary.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 01-15-2016, 08:35 PM
  2. Close open files following "With Workbook.Open" cycle
    By aciccarelli in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-22-2014, 10:58 AM
  3. Create a Command Button to "Save As" and "Close" an Excel Workbook
    By thedunna in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-26-2013, 05:38 PM
  4. need VBA code to open a file type then do a "=countA(A:A)-1" and close it
    By BrandonFromSingapore in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-26-2012, 12:19 PM
  5. Loop through ".DAT" files, open run code, close next
    By Les Stout in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-20-2006, 05:20 AM
  6. [SOLVED] I used "save as" but now can't locate original file
    By Booksmarts in forum Excel General
    Replies: 1
    Last Post: 12-01-2005, 04:20 PM

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