+ Reply to Thread
Results 1 to 7 of 7

How to delete the active workbook via VBA

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

    How to delete the active workbook via VBA

    Hello,

    I would like to know if it's possible for me to delete a .xlsm file simply by clicking a button which is in this very workbook.

    I read something like this

    Please Login or Register  to view this content.
    But all it does is closing the workbook, which I can re-open afterwards, and leaving me in an empty, workbook-free Excel window.

    Do you know why it does that, and how I could completely delete that workbook ?

    Arigato gozaimasu !

    Fran蔞is

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,720

    Re: How to delete the active workbook via VBA

    First, where is your code? If you close the file that contains the code that is running, the code will stop running at the point where the file is closed.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

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

    Re: How to delete the active workbook via VBA

    Hello Jeff,

    My code is indeed in the workbook, but all I wanted to do was to delete the file without leaving any leftover after the operation,
    so I tried to put it all in one place.

    If I really can't do so, I guess I can have another file hidden in my directory... But once again I don't know how to make it.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: How to delete the active workbook via VBA

    With the code in a separate file maybe?

    Please Login or Register  to view this content.

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

    Re: How to delete the active workbook via VBA

    Yeah I tried to do that but the problem is, the name of the file to delete is never the same.
    I thought of something like this :

    Macro in the file I want to delete:
    1- keep the full name and the name of the worksheet in string variables
    2- open the intermediary workbook
    3- put the full name string value in A1 cell and name string value in A2 of the freshly opened worksheet
    4- run the macro in the intermediary file
    then the said macro :
    1- get the name and full name of the deleteable file from A1 & A2
    2- close the deleteable file
    3- kill it
    4- close the intermediary file without saving
    I tried to do something like that but couldn't manage to get rid of that file. I know it works though because by puting the first file's name and path manually I had it deleted.

    I know this isn't code, just directions, but can anybody tell me if the way I try to do it is able to do the trick, or not (and if so, why ? )

    I am going to try some more, and provide my macros' code.
    Last edited by AstroZelda; 06-03-2015 at 05:07 AM. Reason: 1, 2, 3, 5... \o\

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

    Re: How to delete the active workbook via VBA

    Here it is :

    Macro in the target file :
    Please Login or Register  to view this content.
    Macro in the buffer file :
    Please Login or Register  to view this content.

    In the end, the target file still remains undeleted, and Buffer.xlsm doesn't even close...

    I have genuinely no idea why it doesn't do the job...


    EDIT : I found out that the buffer's macro stops after closing the first file... The following appears to work, though !

    So I just have to find why it breaks here, and how to fix it !
    Last edited by AstroZelda; 06-03-2015 at 05:52 AM. Reason: Fresh news !

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

    Re: How to delete the active workbook via VBA

    Calling a VBScript from the workbook works perfectly, at last !

+ 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] Code to detect previous active workbook instead of current active workbook
    By kosherboy in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-25-2014, 01:58 AM
  2. VBA macro for hyperlink to active workbook in the active workbook path
    By Scott Taylor in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-10-2013, 05:37 AM
  3. Delete sheets in Active Workbook
    By pr4t3ek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-28-2008, 01:01 AM
  4. [SOLVED] Delete (kill) active workbook on close: Possible?
    By BEEJAY in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-17-2006, 02:15 PM
  5. [SOLVED] Delete (Kill) Active Workbook
    By stefan via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-09-2005, 09:05 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