0

I have 2 excel workbooks: WB1 (password protected) and WB2. WB2 takes some data from WB1. Everytime I open WB2 i need to type password to WB1 file. Is it possible to make VBA code that type password everytime I open wb2?

1
  • 1
    You would have to put it directly in the code. I assume your workbook is password protected for reason. Placing the password in another document that is not password protected would not be a best practice, in my opinion. Commented Aug 20, 2018 at 13:51

1 Answer 1

1

Yup, and it's actually pretty easy! In workbook 2 you would add this code here to accomplish what you're looking for

Private Sub auto_open()
    Workbooks("workbook 1 name").Unprotect PASSWORD:="my password"
End Sub

Private Sub auto_close()
    Workbooks("workbook 1 name").Protect PASSWORD:="my password"
End Sub

I added the code to re-protect it once you close the second workbook but you might instead want it to be protected under other circumstances, so it's not exactly required.

You should also consider only having workbook 2 unprotect the first workbook during the time that it needs to pull data from workbook 1.

Sign up to request clarification or add additional context in comments.

1 Comment

Suggestion, if you hardcode your password into the VBA program, I would suggest going to Tools > VBAProject Properties > Lock Project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.