I know that an Excel workbook can be password protected. Is there a way to configure an Excel workbook to self-destruct or lock-out further attempts after a password has been entered incorrectly 3x?
Asked
Active
Viewed 730 times
1 Answers
0
First you have to set a reference in the excel reference library by going to:
tools -> references -> "Microsoft Visual Basic For Applications Extensibility 5.3"
(while in vba menu)
Next you would modify your code to look something like this:
Sub DeleteModule()
Dim VBProj As VBIDE.VBProject
Dim VBComp As VBIDE.VBComponent
Dim passwordAttempt As Int
passwordAttempt = 0
Set VBProj = ActiveWorkbook.VBProject
Set VBComp = VBProj.VBComponents("ModuleName")
password = Application.InputBox("Enter Password", "Password Protected")
Select Case password
Case Is = False
'do nothing
Case Is = "easy"
'do something
Case Else
MsgBox "Incorrect Password"
passwordAttempt = passwordAttempt + 1
End Select
if passwordAttempt == 3 Then
VBProj.VBComponents.Remove VBComp
end if
End Sub
I'm not familiar with the proper syntax for setting a password, and I just used this as a reference.
If you need a reference for the self deleting part, you can look here.

Lord Elrond
- 13,430
- 7
- 40
- 80
-
And if you refuse to enable macros on opening? – Solar Mike Jan 02 '19 at 00:26