Password Lock VBA code using VBA

SkywardPalm

Board Regular
Joined
Oct 23, 2021
Messages
61
Office Version
  1. 365
Platform
  1. Windows
I have tried multiple ways of protecting vba code using vba, but I continue to get runtime errors such as "Run-time error '438': Object doesnt support this property or method." I've looked around but haven't found a solution that works for me.


VBA Code:
Sub ProtectVBACode()
    Dim password As String
    password = "pass"
    
    Dim vbProj As Object
    Set vbProj = ThisWorkbook.VBProject
    
    vbProj.Protect password
    
    MsgBox "VBA code is locked for viewing with password."
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Have a look at the thread in the link below where @Jaafar Tribak uses a method other than sendkeys.

 
Upvote 0

Forum statistics

Threads
1,215,124
Messages
6,123,189
Members
449,090
Latest member
bes000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top