Hello!
I have a list of file paths in a workbook, in cells A1:A307. I would like to open some master data files, then open the files listed in Column A one-by-one, update formula values that are referring to the master data files, save them, and then close them.
If the file is unable to be opened, I would like for "Review" to be placed in Column B next to the path.
I have the following code, but when I run it, it appears to not have attempted to open all the files listed in Column A, but it doesn't stop working on any specific line of code either. I placed some dummy erroneous paths at the bottom of the list, and these aren't getting flagged with the "Review" designation. Additionally, the legitimate files do not show a modified date/time corresponding to the time that I attempt to run the macro.
Have I gone wrong somewhere in my error handling? It seemed simple enough, but I guess I was wrong!![Laugh :LOL: :LOL:](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
TIA!
I have a list of file paths in a workbook, in cells A1:A307. I would like to open some master data files, then open the files listed in Column A one-by-one, update formula values that are referring to the master data files, save them, and then close them.
If the file is unable to be opened, I would like for "Review" to be placed in Column B next to the path.
I have the following code, but when I run it, it appears to not have attempted to open all the files listed in Column A, but it doesn't stop working on any specific line of code either. I placed some dummy erroneous paths at the bottom of the list, and these aren't getting flagged with the "Review" designation. Additionally, the legitimate files do not show a modified date/time corresponding to the time that I attempt to run the macro.
Have I gone wrong somewhere in my error handling? It seemed simple enough, but I guess I was wrong!
TIA!
Code:
Sub openandsave()
Dim lastRow As Long
Application.DisplayAlerts = False
Application.ScreenUpdating = False
With ActiveSheet
lastRow = Range("A1").End(xlDown).Row
End With
'Open all database files
Workbooks.Open Filename:= _
"C:\Test\Current.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"C:\Test\DataLinks.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"C:\Test\Market Statistics.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"C:\Test\PartnershipPrices.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"C:\Test\Positions.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"C:\Test\Options Database.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"C:\Test\PricesNewInvestrak.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"C:\Test\Weekly Investrak List.xls", UpdateLinks:=3
'Loop through files, save, and close
For i = 1 To lastRow
On Error GoTo allocationerror:
With Workbooks.Open(Range("A" & i), UpdateLinks:=3)
.Close SaveChanges:=True
End With
Next i
allocationerror:
Range("B" & i).Value = "Review"
Resume Next
'Close database workbooks
Workbooks("Current.xls").Close SaveChanges:=True
Workbooks("DataLinks.xls").Close SaveChanges:=True
Workbooks("Market Statistics.xls").Close SaveChanges:=True
Workbooks("PartnershipPrices.xls").Close SaveChanges:=True
Workbooks("positions.xls").Close SaveChanges:=True
Workbooks("PricesNewInvestrak.xls").Close SaveChanges:=True
Workbooks("Options Database.xls").Close SaveChanges:=True
Workbooks("Weekly Investrak List.xls").Close SaveChanges:=True
Application.ScreenUpdating = True
End Sub