Excel

Code for a self-destructing Workbook

Ease of Use

Easy

Version tested with

2003 

Submitted by:

brettdj

Description:

The file containing this code is closed and permanently deleted. **Caution** - use this code with care 

Discussion:

Perhaps a workbook should expire after a certain date, or somone fails to correctly answer a password query and the file is deleted to prevent unauthorised access. This code could be used in conjuction with johnske's http://www.vbaexpress.com/kb/getarticle.php?kb_id=475 to delete a workbook once its trial period has expired. 

Code:

instructions for use

			

Option Explicit Sub KillMe() With ThisWorkbook .Saved = True .ChangeFileAccess Mode:=xlReadOnly Kill .FullName .Close False End With End Sub

How to use:

  1. Copy the code above.
  2. Open your workbook.
  3. Hit Alt+F11 to open the Visual Basic Editor (VBE).
  4. From the menu, choose Insert-Module.
  5. Paste the code into the code window at right.
  6. Close the VBE, and save the file if desired.
 

Test the code:

  1. Run the macro by going to Tools-Macro-Macros and double-click KillMe.
  2. **** This code will kill the file it is run from! ****
 

Sample File:

WorkbookSuicide(KB23).zip 9.36KB 

Approved by mdmackillop


This entry has been viewed 790 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express