Hello!
I have a number of file paths listed in Column A of Sheet1 that have to be opened and saved daily. There are formulas in these sheets that are linked back to other data sheets that should remain open the whole time.
However, the current macro I have fails to a full stop if one of the files is moved or replaced. Instead of this, I would like to have the word "Review" in Column B next to the file that could not be opened, and for the macro to continue on to the next file.
Here's what I have so far:
TIA!
I have a number of file paths listed in Column A of Sheet1 that have to be opened and saved daily. There are formulas in these sheets that are linked back to other data sheets that should remain open the whole time.
However, the current macro I have fails to a full stop if one of the files is moved or replaced. Instead of this, I would like to have the word "Review" in Column B next to the file that could not be opened, and for the macro to continue on to the next file.
Here's what I have so far:
Code:
Sub openandsave()
Dim lastRow As Long
Application.DisplayAlerts = False
Application.ScreenUpdating = False
With ActiveSheet
lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
'Open all database files
Workbooks.Open Filename:= _
"...\Current.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"...\DataLinks.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"...\Market Statistics.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"...\PartnershipPrices.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"...\Positions.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"...\Options Database.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"...\PricesNewInvest.xls", UpdateLinks:=3
Workbooks.Open Filename:= _
"...\Weekly Invest List.xls", UpdateLinks:=3
For i = 1 To lastRow
On Error Resume Next
With Workbooks.Open(Range("A" & i), UpdateLinks:=3)
.Save
.Saved = True
.Close
End With
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("PricesNewInvest.xls").Close SaveChanges:=True
Workbooks("Options Database.xls").Close SaveChanges:=True
Workbooks("Weekly Invest List.xls").Close SaveChanges:=True
Application.ScreenUpdating = True
End Sub
TIA!