VBA Macros - Protecting
VBA Macros - Protecting
VBA Add-ins
Protecting
Macros
You can protect your VBA projects with passwords although your code is
Troubleshooting ... not 100% secure.
Adding a password will deter the average user though.
Visual Basic Editor*
You can protect your code by locking the project for viewing and providing
Macro Settings ... a password (Tools > VBAProject Properties)(Protection tab, "Lock
project for viewing").
Running ...
SS
Shortcut Keys
Recording
The name might vary depending whether you have renamed the project
Deleting
Saving
You cannot apply a locked this project password if there is no VBA code
Timing and the file extension is .xlsx
Protecting
Undoing VBAProject
Application Class The default name used for every VBA project is "VBAProject"
You can change the name of your project to something else, although not
Interrupting
many people do this.
Best Practices If the name of your project has been changed the menu option will not be
(Tools > VBAProject Properties) but will be the new name of the project.
Code Modules
Subroutines ...
Functions ...
Arguments ...
Is the Project Protected
Advanced ...
ErrorHandler:
Updates ... Project_IsProtected = True
End Sub
Feedback
Updated: 07
December 2016 Project Is Unviewable
KB - 211792
Save the Excel workbook (.xls) file into an add-in (File > SaveAs.....)
After you have the saved add-in (.xla), close the Excel workbook (.xls)
Double click on the add-in to open it
Press Alt+F11 to access the add-in's vba project
Lock the vba-project with a password
Double-click on the "ThisWorkbook" code module
Press F4 to open the Properties window
Change the "IsAddin" status to FALSE
Return to Excel by Pressing Alt+Q (or close the vbe window)
Go to Tools > Share Workbook
When the dialog appears, check the box for: (Allow changes by.....)
Press OK to close the Dialog
When prompted to save, Press OK
Press Ok to accept that "macros cannot be accessed"
You should feel giddy at this point because you just realized what you have
been missing right under your nose
Verify that the [SHARED] appears in the application title bar
Now save the workbook again as an Add-in (File > SaveAs...) overwriting
the previous one
Close this Excel workbook without saving the changes (you don't need it)
Test out your newly saved add-in (open it, access the vbe, try to expand
the project window, you should get the new message "Project is
Unviewable"
Sub PasswordBreaker2()
Dim i As Integer, j As Integer, k As Integer
Dim l As Integer, m As Integer, n As Integer
Dim i1 As Integer, i2 As Integer, i3 As Integer
Dim i4 As Integer, i5 As Integer, i6 As Integer
On Error Resume Next
For i = 65 To 66: For j = 65 To 66: For k = 65 To 66
For l = 65 To 66: For m = 65 To 66: For i1 = 65 To 66
For i2 = 65 To 66: For i3 = 65 To 66: For i4 = 65 To 66
For i5 = 65 To 66: For i6 = 65 To 66: For n = 32 To 126
ActiveSheet.Unprotect Chr(i) & Chr(j) & Chr(k) & _
Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & Chr(i3) & _
Chr(i4) & Chr(i5) & Chr(i6) & Chr(n)
If ActiveSheet.ProtectContents = False Then
MsgBox "One usable password is " & Chr(i) & Chr(j) & _
Chr(k) & Chr(l) & Chr(m) & Chr(i1) & Chr(i2) & _
HookBytes(0) = &H68
MoveMemory ByVal VarPtr(HookBytes(1)), ByVal VarPtr(p), 4
HookBytes(5) = &HC3
Sub unprotected()
If Hook Then
MsgBox "VBA Project is unprotected!", vbInformation, "*****"
End If
End Sub
Then open the workbook that contains the password protected VBA
project.
Important
If you VBA Project contains NO VBA code but is password protected it will
be treated exactly the same as a project that does not contain VBA code.