+ Reply to Thread
Results 1 to 4 of 4

VBA to open new workbook and run macro from new workbook, which closes old workbook

  1. #1
    Forum Contributor
    Join Date
    07-22-2009
    Location
    Minneapolis, MN
    MS-Off Ver
    2016
    Posts
    220

    VBA to open new workbook and run macro from new workbook, which closes old workbook

    Hi,
    I'm running in to a problem I can't seem to figure out. I have two spreadsheets located in a folder, "BOOK1" and "BOOK2".

    The intended process is to run MACRO1 on BOOK1. MACRO1 will open BOOK2, then call MACRO2 on BOOK2. MACRO2 will close BOOK1 without saving, then delete BOOK1 from folder


    Using the code below, everything runs fine until line 2 on MACRO2; at that point the macro just stops for some reason and I don't know why.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Can anyone please let me know how MACRO2 needs to change so it gets through line 5? Thanks!

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: VBA to open new workbook and run macro from new workbook, which closes old workbook

    Hi,

    Even the line 2 on MACRO2 is fixed (so BOOK1 is closed), the rest of MACRO2 will not be executed, because as soon as the BOOK1 is closed (by line 2 statement), so the rest of code will terminated.

    If you curious howto fix this line 2 :

    Please Login or Register  to view this content.


    So the trick is using timer function (Application.OnTime) to launch sub MACRO2 later, but before that happen, close BOOK1 by itself first. Please look at my attached file (zip file, contains 2 file : Book1.xls and Book2.xls)

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Regards
    Attached Files Attached Files
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  3. #3
    Forum Contributor
    Join Date
    07-22-2009
    Location
    Minneapolis, MN
    MS-Off Ver
    2016
    Posts
    220

    Re: VBA to open new workbook and run macro from new workbook, which closes old workbook

    Simple. Concise. Functional. Beautiful work!

    Thank you SO much for your help!

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: VBA to open new workbook and run macro from new workbook, which closes old workbook

    You are welcome, and many thanks for the reputation points.

    Regards

+ 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. The workbook closes, but the excel application remains open
    By kmakjop in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2014, 03:38 PM
  2. Macro to open a closed workbook and select copy cells into an open workbook
    By helloganesh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2013, 02:00 PM
  3. Save an open workbook, then open template workbook and close the saved workbook
    By ondvirg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-27-2009, 10:20 PM
  4. Auto-open macro closes workbook - how do I access its contents?
    By audax in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-12-2009, 02:13 PM
  5. [SOLVED] VBAProject remains open after Workbook closes
    By tchid2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-17-2006, 07:15 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