View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default How to make VBA code to self-destroy itself?

http://groups.google.com/groups?thre...%40tkmsftngp07


''Needs a reference to the VB Extensibility library set
'Removes from active workbook all:
''Regular modules
''Class modules
''Userforms
''Code in sheet and workbook modules
''Non built-in references
''Excel 4 macro sheets
''Dialog sheets
Sub RemoveAllCode()
Dim VBComp As Object, AllComp As Object, ThisProj As Object
Dim ThisRef As Reference, WS As Worksheet, DLG As DialogSheet
Set ThisProj = ActiveWorkbook.VBProject
Set AllComp = ThisProj.VBComponents
For Each VBComp In AllComp
With VBComp
Select Case .Type
Case vbext_ct_StdModule, vbext_ct_ClassModule, _
vbext_ct_MSForm
AllComp.Remove VBComp
Case vbext_ct_Document
.CodeModule.DeleteLines 1, .CodeModule.CountOfLines
End Select
End With
Next
For Each ThisRef In ThisProj.References
If Not ThisRef.BuiltIn Then ThisProj.References.Remove ThisRef
Next
Application.DisplayAlerts = False
For Each WS In Excel4MacroSheets
WS.Delete
Next
For Each DLG In DialogSheets
DLG.Delete
Next
End Sub

above previously posted by Jim Rech.

--
Regards,
Tom Ogilvy

"count" wrote in message
...
Thanks Frank,
I still need the answer though.
The app and code are mine and users agree that it's better for them to

have
dead application rather than one that lies about tax rebate rates - stuff

is
serious!
They can disable that code, you say - that's why I prefer app to castrate
itself. They can still use backup and reimport missing module but in this
case my butt is safe.
So question is still open
Paul

Użytkownik "Frank Kabel" napisał w wiadomości
...
Hi Paul
I wouldn't recommend this.
First: Easy to circumvent by an experienced user by disabling this code
part
Second: Not sure if you're allowed to do 'deleting' code and the

possible
legal consequences.

Bottom line: In Excel there's no real way to protect/secure your code

"count" wrote:

Hi,
I need to ensure that users keep updating software in VBA. So I need to
warn
them, say 1 month in advance and past that, I need to disable their
access
to crucial module.
I thought of removing that module. How do I do that programmatically?
TIA
Paul