![]() |
Updating workbook from protected workbooks...
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 |
Updating workbook from protected workbooks...
Hi all. Please ignore as I have fixed it now.
"ajayb" wrote: 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 |
All times are GMT +1. The time now is 05:38 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com