is there any code that can make workbook perform self destruction..inside..


Posted by kid on April 28, 2000 9:33 PM

let say..i have 3 sheet in my workbook..
is there any VB code that can command this
workbook to self destruction depend on the time
let say after 1 month..it cannot be opened again..thanks

Posted by Celia on April 30, 2000 6:25 AM


Kid
I don’t think that there is a way for a workbook to delete itself.
However, you could have a macro (in the workbook module) that runs whenever the workbook is opened and that automatically deletes all sheets after a specified date.
For instance, the following will automatically insert a blank sheet and then delete all the other sheets if the workbook is opened after May 4, 2000 (i.e. 36650) :-

Private Sub Workbook_Open()
Dim sheet As Object
If Now() > 36650 Then
Application.DisplayAlerts = False
Sheets.Add.Name = "BLANK"
For Each sheet In Sheets
If sheet.Name <> "BLANK" Then
sheet.Delete
End If
Next
MsgBox "All data has just been deleted from this workbook"
End If
End Sub

Before testing the macro, make sure that either you use it on a file that contains unwanted data or you have a back-up copy of the file.
Also, once the specified date has been passed, you will not be able to access the workbook to change the date or gain access to any of the data.

Celia




Posted by mikefaulkner on June 07, 2000 12:54 PM

That would work, but if this is a security issue, there are several ways around this.

#1 Someone can change the system time if they know when the workbook is set to be "destructed".

#2 Macros can simply be disabled - which will not allow the destructive code to run.

Just something to keep in mind if this method is to be used for highly secure data or around computer savvy people.