|
|
|
|
|
|
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:
|
- Copy the code above.
- Open your workbook.
- Hit Alt+F11 to open the Visual Basic Editor (VBE).
- From the menu, choose Insert-Module.
- Paste the code into the code window at right.
- Close the VBE, and save the file if desired.
|
Test the code:
|
- Run the macro by going to Tools-Macro-Macros and double-click KillMe.
- **** 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.
|
|