I am using following code to refresh the workbook. However, If I have more than one workbook (for example 10) then how do I optimize my code.
OR
Do I have to repeat code 10 times? Any idea, please.
OR
Do I have to repeat code 10 times? Any idea, please.
Code:
Sub refresh()
Application.ScreenUpdating = False
Dim filename1 As String
filename1 = "C:\Users\Cost.xlsx"
If Len(Dir(filename1)) = 0 Then
MsgBox "Could not find the file " & filename1, vbExclamation, "File Not Found"
Exit Sub
Else
Workbooks.Open filename1, ReadOnly:=False, IgnoreReadOnlyRecommended:=True
Workbooks(ThisWorkbook.Name).RefreshAll
Windows("Cost.xlsx").Activate
ActiveWorkbook.Save
ActiveWorkbook.Close
End If