A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data
Hi
There is no supported VBA method such as VBProject.Unprotect "password". A protected VBA project must be unlocked through the VBA editor. Knowing the password does not allow another workbook to unlock it through the standard VBA object model.
As a workaround, you can try open Workbook2, then unlock it manually:
- Press Alt+F11.
- In Project Explorer, expand Workbook2’s project.
- Enter its password when prompted.
- Run the macro in Workbook1 that accesses Workbook2’s VBproject
For example, after it has been unlocked:
Sub WorkWithWorkbook2Project()
Dim wb2 As Workbook
Dim vbProject As Object
Set wb2 = Workbooks("Workbook2.xlsm")
Set vbProject = wb2.VBProject
Debug.Print vbProject.Name
End Sub
To use VBProject, you need to enable:
- Open File > Options > Trust Center > Trust Center Settings
- Go to Macro Settings > Select Trust access to the VBA project object model
If using early binding, also select:
- VBE > Tools > References > Microsoft Visual Basic for Applications Extensibility 5.3
Once the project is unlocked, VBA code in Workbook1 can access or modify Workbook2’s VBA components. If the requirement is only to run a public macro stored in Workbook2, unlocking the VBA project is not necessary. Workbook1 can call the macro using Application.Run.
For more information, please refer to the following link:
- 2.3.1.16 ProjectPassword
- Set project properties
- VBA - How can I password protect moldules using code?
- VBA Project Password
This link is shared by community members for your convenience. It points to a third-party site that is not managed or verified by Microsoft. I can’t guarantee the quality, safety, or suitability of any content or software found there. Please review carefully and make sure you understand any potential risks before using it.
I hope this points you in the right direction and feel free to share the validation testing results if you need further assistance.
Thank you for your understanding, and I wish you a wonderful day ahead.
Best regards,
If the answer is helpful, please click "Yes" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in forum documentation to enable e-mail notifications if you want to receive the related email notification for this thread.