Reputation: 3
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?
Upvotes: 0
Views: 67
Reputation: 3257
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.
Upvotes: 1