VBA project password

Turner Macy 0 Reputation points
2026-08-26T00:42:16.5733333+00:00

Hello

By VBA I first open Workbook1 and then Workbook 2.

From workbook1 I need VBA code to unprotect the VBA project from workbook2.

I know the password for the workbook 2 project.

How do I do it? Thanks in advance.

Microsoft 365 and Office | Excel | For business | Windows
0 comments No comments

1 answer

Sort by: Most helpful
  1. Killian N 3,470 Reputation points Independent Advisor
    2026-08-26T01:56:25.93+00:00

    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:

    1. Press Alt+F11.
    2. In Project Explorer, expand Workbook2’s project.
    3. Enter its password when prompted.
    4. 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:

    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.  

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.