+ Reply to Thread
Results 1 to 4 of 4

Closing another workbook stops the macro in the initial one

  1. #1
    Registered User
    Join Date
    05-07-2015
    Location
    Angouleme, France
    MS-Off Ver
    2013
    Posts
    48

    Closing another workbook stops the macro in the initial one

    Hello everyone,

    I am currently trying to delete an Excel file from the inside.
    Knowing that it's impossible while it's open, I tried to do like so :

    1:Open another workbook
    2:Give it the first workbook's infos (name, path..) by writing it in the sheet
    3:Run the second workbook macro

    That macro does the following :

    1:Get the first workbook's infos from the sheet
    2:Close the first workbook
    3:Kill it
    4:Close the second workbook

    The problem is, when closing the first workbook, it closes the first macro which aborts the second one. Basically, everything stops after closing the first workbook.

    I tried executing the second macro with a workbook_open() event but even with a delay it doesn't get the first workbook's infos.

    I am a bit desperate, your help would be much appreciated !

    Thank you,

    François

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Closing another workbook stops the macro in the initial one

    Move Your Macro into your Personal Workbook.

    Then you can close your workbook at the macro will continue to run.

    If you are not sure how to access your personal workbook then

    record a new macro ensuring you select Personal workbook when asked where you want it stored

    Then step through that macro, this will open the personal workbook for you

    Paste your code there and quit excel

    You will be asked if you want to save changes to the personal workbook, select yes.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

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

    Re: Closing another workbook stops the macro in the initial one

    You can delete a file from the inside without using another macro or workbook. Doing so first requires you to change the environment variable on that workbook so Excel thinks it is OK to delete that workbook, basically turning off the safeguards on that one file.

    So, in a Workbook_Open() event something like this:

    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!)

  4. #4
    Registered User
    Join Date
    05-07-2015
    Location
    Angouleme, France
    MS-Off Ver
    2013
    Posts
    48

    Re: Closing another workbook stops the macro in the initial one

    Sorry guys, I didn't received response notifications :/

    I somehow managed to do it using a vbscript with arguments, which is pretty efficient.

    Nevertheless, I keep those solution as I surely will need them soon. Thank you !

    François

+ 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. This Macro stops working when i share my workbook
    By gostavee in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2015, 07:13 AM
  2. add a sheet to an opened workbook. Macro stops
    By fabdav in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-21-2014, 01:30 PM
  3. macro for printing charts in workbook stops working
    By jolynn in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-11-2013, 01:54 PM
  4. [SOLVED] Macro stops executing if another workbook is open
    By 4evra in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-01-2013, 12:32 PM
  5. Macro stops after opening another workbook
    By biomix in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2012, 07:56 PM

Tags for this Thread

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