Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA Self-Destruct Switch

Tags:

excel

vba

I have had my first "Client-took-my-work-and-then-ghosted-me-without-paying" experience. For the future, I want to put in a killswitch, disguised as a regular macro, which makes the whole thing unusable. That way, even if they hire someone to crack the password and remove my "Your trial has expired..." check, a normal-looking macro (Something like "Fix_Sheet_Formatting") would be easily overlooked and run, destroying everything and saving the changes.

However, that leaves the VBA... We're talking a full purge here, so everything must go. I'll figure out how to do all of this on my own, I just don't want to waste time pursuing something that isn't possible:

Can VBA code delete itself from a workbook while running or does it have to be deleted from a macro on another workbook? And would deleting the code cause the macro to stop running, or can I have it delete everything except a nasty MsgBox after everything is done?

like image 857
C-Love511 Avatar asked Mar 11 '23 10:03

C-Love511


2 Answers

I'll leave the comments to debating whether or not this is a good idea (IMHO it probably isn't). As to the question itself, of course it's possible, and won't interrupt macro execution:

Public Sub Example()
    Dim proj As Object
    Set proj = ThisWorkbook.VBProject
    Dim comp As Object
    For Each comp In proj.VBComponents
        With comp.CodeModule
            .DeleteLines 1, .CountOfLines
            If comp.Name = "ThisWorkbook" Then
                .InsertLines 1, "Private Sub Workbook_Open()" & vbCrLf & _
                                vbTab & "MsgBox ""Where's my money, @#$%&!?""" & vbCrLf & _
                                "End Sub"
            End If
        End With
    Next
    ThisWorkbook.Save
End Sub

Obfuscation is an exercise for the reader.

like image 155
Comintern Avatar answered Mar 21 '23 02:03

Comintern


Put a loop with due date as your payment data . Inside write code to get macro into infinity loop or to delete code. If payment happens on time then just comment above piece of code or else just wait client come back to you on next day defined in loop.

like image 32
Yogesh Avatar answered Mar 21 '23 02:03

Yogesh