Updating workbook from protected workbooks...

A

ajayb

Hi all,

I have a workbook with links in it. The links go to protected workbooks and
I have ued the following code (posted in an earlier post 21/05/07 by Dave
Peterson - thanks Dave!) which works fine if I put it in a seperate book:

Sub UpdatingSheets()

Dim myFileNames As Variant
Dim myPasswords As Variant
Dim iCtr As Long
Dim myRealWkbk As Workbook
Dim myRealWkbkName As String
Dim wkbk As Workbook

myRealWkbkName = "C:\Documents and Settings\abus9580\Desktop\Main.xls"

myFileNames = Array("C:\Documents and
Settings\abus9580\Desktop\Addresses1.xls", "C:\Documents and
Settings\abus9580\Desktop\Ages.xls")

myPasswords = Array("test", "test")

If UBound(myFileNames) <> UBound(myPasswords) Then
MsgBox "check names & passwords--qty mismatch!"
Exit Sub
End If

Set myRealWkbk = Workbooks.Open(Filename:=myRealWkbkName, UpdateLinks:=0)
For iCtr = LBound(myFileNames) To UBound(myFileNames)
Set wkbk = Nothing
On Error Resume Next
Set wkbk = Workbooks.Open(Filename:=myFileNames(iCtr), _
Password:=myPasswords(iCtr))
On Error GoTo 0

If wkbk Is Nothing Then
MsgBox "Check file: " & myFileNames(iCtr)
Exit Sub
End If

wkbk.Close savechanges:=False
Next iCtr

End Sub

My question is, how do I use it in the Main workbook because it doesn't seem
to work?

Any help greatly appreciated.

Andy
 

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

Top