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?
-
1You 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.Brent– Brent2018-08-20 13:51:01 +00:00Commented Aug 20, 2018 at 13:51
Add a comment
|
1 Answer
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.
1 Comment
Kubie
Suggestion, if you hardcode your password into the VBA program, I would suggest going to Tools > VBAProject Properties > Lock Project