PDA

View Full Version : Solved: Workbook links need password



canucklady
04-26-2007, 01:23 PM
Hello everyone,

This seems like an easy enough question, but can't seem get my code to work.

I am trying to open a workbook, which is has a link to workbook which is password protected. With the code I have the it still asks me for password, any ideas?

Sub OpenWB()
Workbooks.Open Filename:= _
"c:\workbook1.xls" _
, UpdateLinks:=3
ActiveWorkbook.UpdateLink Name:= _
"c:\workbook2.xls" _
, Type:=xlExcelLinks, Password:="password"
ActiveWorkbook.Save
ActiveWindow.Close
End Sub

canucklady
06-20-2007, 09:10 AM
Anyone?

canucklady
06-20-2007, 11:08 AM
Found solution here:

http://www.ozgrid.com/forum/showthread.php?t=28111&highlight=linked+workbooks

Sub LinksUpdate()
Application.ScreenUpdating = False
'Open Ref.xls file.
RefPath = "j:\password\"
Workbooks.Open Filename:=RefPath & "ref.xls", Password:="p1", UpdateLinks:=3
Workbooks("ref.xls").Activate
Worksheets("One").Select
Rmax = Cells(65536, 2).End(xlUp).Row
For r = 2 To Rmax
Workbooks("ref.xls").Activate
Worksheets("One").Select
Pth = Cells(r, 1).Value & "\"
fName = Cells(r, 2).Value & ".xls"
pw = Cells(r, 3).Value
Workbooks.Open Filename:=Pth & fName, Password:=pw, UpdateLinks:=3
ThisWorkbook.Activate
Workbooks(fName).Close SaveChanges:=False
Next r
Workbooks("ref.xls").Close SaveChanges:=False
Application.ScreenUpdating = True
End Sub