Is a "Kill the Worksheet" command possible?

  • Thread starter Thread starter Scot
  • Start date Start date
S

Scot

What command can I write into a worksheet, and keep it hidden, that will
kill the worksheet on a specified date? In other words, if I create a
worksheet and want it to only be used for a specific time period, what
command can I write/embed and hide somewhere in the worksheet that will
cause it to virtually disappear, or delete itself, on a specified future
date?
 
Scot,

You would need to use a auto-open macro or the worksheet open event to check
the date, and then call the sub Suicide at the correct time.

See the code below, posted by Chip Pearson.

HTH,
Bernie
MS Excel MVP

Sub Suicide()
Dim FName As String
Dim Ndx As Integer
With ThisWorkbook
.Save
For Ndx = 1 To Application.RecentFiles.Count
If Application.RecentFiles(Ndx).Path = .FullName Then
Application.RecentFiles(Ndx).Delete
Exit For
End If
Next Ndx
.ChangeFileAccess Mode:=xlReadOnly
Kill .FullName
.Close SaveChanges:=False
End With
End Sub

I think it was Bob Umlas who posted the real gem of the ChangeFileAccess
property. The rest is my fluff.
 
Caveats needed!

Users can turn off macros, and if they do so the approach Bernie gave won't
work. Users can also make multiple copies of files, so if one is deleted using
this approach, others could be opened with macros disabled. Also, unless you
protect the VBA module containing this macro, your users could find it in the
VBE and gut it or delete it. Even if you do protect the module containing the
Suicide macro, users could effectively disable it by creating another module and
putting a do-nothing macro named Suicide in it, thus causing a run time error
when an event handler attempts to run the original Suicide macro. Even if you
could specifically refer to the Suicide macro in a specific module, your users
could use a hex editor to rename that module.

The lesson that you must learn is that there is NO WAY to apply an expiration
date to an Excel workbook that can't be defeated by a moderately knowledgeable
Excel user. Heck, the paragraph above is a basic How-To for defeating you.

If you want to protect your software IP, use a real programming language and
compile your software into a standalone executable or DLL. Distributing IP you
want to disable after a limited time in any document format is unwise.
 
Back
Top