Hi,
Thanks to help via multiple ways I have a VBA setup in the situation I have three files already open. For which two are used to provide input to 60 separate files, and the 60 separate files provide input to the third file. All are office 365 sharepoint files. With the three files open, the VBA opens the 60 files one by one, recalculated, and updating the values from and to the other three files and then closes each file before opening the next of the 60. However the VBA does take me 10 minutes or more each time I run it. And sadly due to company decissions running Excel in 32 bit. Does anybody have an idea on how to optimize the following code? I think it will also be too risky to disable calculations, than open 60 files, restart calculations, after calculations close all 60 files? But open to any suggestions!
Thanks to help via multiple ways I have a VBA setup in the situation I have three files already open. For which two are used to provide input to 60 separate files, and the 60 separate files provide input to the third file. All are office 365 sharepoint files. With the three files open, the VBA opens the 60 files one by one, recalculated, and updating the values from and to the other three files and then closes each file before opening the next of the 60. However the VBA does take me 10 minutes or more each time I run it. And sadly due to company decissions running Excel in 32 bit. Does anybody have an idea on how to optimize the following code? I think it will also be too risky to disable calculations, than open 60 files, restart calculations, after calculations close all 60 files? But open to any suggestions!
Sub Update()
Dim lr As Long
Dim i As Integer
Dim WBSsource As Workbook
Dim FileNames As Variant
Dim msg As String
Application.ScreenUpdating = False
Application.EnableEvents = False
With ThisWorkbook.Sheets("Macro")
lr = .Cells(.Rows.Count, "A").End(xlUp).Row
FileNames = .Range("a1:a" & lr).Value
End With
For i = LBound(FileNames, 1) To UBound(FileNames, 1)
On Error Resume Next
If FileNames(i, 1) Like "*.xlsm" Then
Set WBSsource = Workbooks.Open(FileNames(i, 1), _
ReadOnly:=False, _
UpdateLinks:=True, _
Password:="")
If Err = 0 Then
With WBSsource
ActiveWorkbook.Save
ActiveWindow.Close
End With
Else
msg = msg & FileNames(i, 1) & Chr(10)
On Error GoTo 0
End If
End If
Set WBSsource = Nothing
Next i
If Len(msg) > 0 Then
MsgBox "The Following Files Could Not Be Opened" & _
Chr(10) & msg, 48, "Error"
End If
ActiveWorkbook.AutoSaveOn = True
Application.ScreenUpdating = True
Application.EnableEvents = True
MsgBox "All files have been updated"
End Sub