vba code for opening password protected workbook

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is it possible for somebody to tell me the code i would need to open up a
password protected workbook, update the linked worksheets inside, then save
and close.
 
Sub OpenPassword()
Dim wbk As Workbook

Application.DisplayAlerts = False

Set wbk = Workbooks.Open(Filename:="", _
UpdateLinks:=True, _
Password:="")

With wbk
.Save
.Close
End With

Set wbk = Nothing
End Sub
 
Thanks guys thats brilliant, unfortunately it used to ask me for 2 passwords
and it still tells me to enter a password for write access or open as read
only, is there a way to bypass this password too?
 
See the example on my page

Set mybook = Workbooks.Open(MyPath & MyFiles(Fnum), _
Password:="ron", WriteResPassword:="ron", UpdateLinks:=0)
 
Hi Ron,

Sorry to be a pain but i cant get this to work, im obviously doing something
wrong, do i just need those 2 lines you gave me or is there something else i
need to insert, both my files are in the same folder as suggested.
 
In Dave's code you see

Password:="ron"

Now add this
WriteResPassword:="ron",
 
Hi Ron, i've copied Dave's code in like you said and added the line with the
write password instruction but it gives me a compile error/syntax error when
i try to run it. This is my code as i currently have it, i have tried putting
brackets and commas etc to separate the 2 password lines, i've even tried
them on the same line but everything returns the compile error.

Thanks

Carl


Sub OpenPassword()
Dim wbk As Workbook

Application.DisplayAlerts = False

Set wbk = Workbooks.Open(Filename:="e:\rota stuff\nick rota template", _
UpdateLinks:=True, _
Password:="united1")
WriteResPassword:="united1")
With wbk
..Save
..Close

End With

Set wbk = Nothing

End Sub
 
Use it like this

Set wbk = Workbooks.Open(Filename:="e:\rota stuff\nick rota template", _
Password:="united1", WriteResPassword:="united1", UpdateLinks:=True)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top