+ Reply to Thread
Results 1 to 5 of 5

Hand control to another workbook to delete current workbook

  1. #1
    Registered User
    Join Date
    02-07-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    27

    Question Hand control to another workbook to delete current workbook

    I'm trying to delete a workbook that's currently open, but it needs to be done in following manner;

    1. Open workbook1 & run some macros.
    2. Workbook1 opens workbook2.
    3. Workbook2 runs some macros.
    3. Workbook2 deletes workbook1.


    I've tried following but it doesn't work & it doesn't generate any errors at all. It just stops when workbook1 is closed.

    Workbook 1

    Please Login or Register  to view this content.

    Workbook 2

    Please Login or Register  to view this content.
    I've tried few other things, even through ThisWorkbook Activate, but as soon as first workbook is closed it's the same issue everything stops.


    So is there a way to hand control over to another workbook & do this? It seems like a file handle control issue but not sure how would do this.

  2. #2
    Forum Expert BadlySpelledBuoy's Avatar
    Join Date
    06-14-2013
    Location
    East Sussex, UK
    MS-Off Ver
    365
    Posts
    7,498

    Re: Hand control to another workbook to delete current workbook

    Difficult to be sure without sight of the files involved, but try adding the below line just before your wb.close line.
    Please Login or Register  to view this content.
    BSB

  3. #3
    Registered User
    Join Date
    02-07-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    27

    Re: Hand control to another workbook to delete current workbook

    I've just tried that, same issue still.
    The files in question are very bare bones as I've stripped them back to try & get this to work.

    I guess a question would be, should this work?

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    82,386

    Re: Hand control to another workbook to delete current workbook

    There are instructions at the top of the page explaining how to attach your sample workbook.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    02-07-2016
    Location
    London, England
    MS-Off Ver
    2013
    Posts
    27

    Re: Hand control to another workbook to delete current workbook

    I've uploaded 2 files, both contain macros. They both need to be in the same folder.

    File2Delete contains a button & starts it, passes workbook object to ParentMain.
    ParentMain contains macro that is supposed to delete the first one, which I've replaced with MsgBox so can see the issue.

    Soon as File2Delete is closed, nothing else works & any strings created before it's closed that get stored in ParentMain is lost.
    Attached Files Attached Files

+ 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. [SOLVED] VBA Macro pull a certain cell in closed workbook and copy/paste into current workbook
    By Hoover5896 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2017, 01:36 AM
  2. In Current workbook- copy sheets from other workbooks and save in current workbook
    By johnnywinter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2016, 08:41 PM
  3. [SOLVED] Opening new workbook and pasting values into current workbook - code issues
    By Stew1234 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-15-2014, 07:56 AM
  4. Replies: 2
    Last Post: 01-06-2013, 04:27 PM
  5. on-hand type workbook
    By Slashalot in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-16-2007, 01:56 PM
  6. Delete the current workbook
    By Josh_123456 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-19-2006, 02:16 PM
  7. Addin macro to delete names in current workbook
    By David Iacoponi in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-15-2005, 02:05 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