Hi all,
I am trying to open many workbooks which are selected by the user in the below code.
The problem is that it is very slow , it takes too much time to open comparing with manually opening the same workbooks.
I need to make this code super fast. Please tell me how ?
I am attaching the workbook that I try to open. It takes +/- 20 seconds to open now using below code.
Sub openWorkBooks()
'PURPOSE: Determine how many seconds it took for code to completely run
Dim StartTime As Double
Dim SecondsElapsed As Double
'Remember time when macro starts
StartTime = Timer
'On Error Resume Next
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim fd As Office.FileDialog, strFile As String, I As Integer
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.Filters.Clear
.Filters.Add "Excel Files", "*.xlsx?,*.xls", 1
.Title = "Choose an Excel file"
.AllowMultiSelect = True
.InitialFileName = "D:\D\WORK\Spreadsheets" & "\"
If .Show = True Then
For I = 1 To .SelectedItems.Count
Application.AskToUpdateLinks = False
Application.DisplayAlerts = False
Application.EnableEvents = False
'Opening selected file
Application.Workbooks.Open .SelectedItems(I)
'MsgBox "Workbook name is " & Workbooks.Open.Name
Application.AskToUpdateLinks = True
Application.DisplayAlerts = True
Application.EnableEvents = True
Next I
End If
End With
'Determine how many seconds code took to run
SecondsElapsed = Round(Timer - StartTime, 2)
'Notify user in seconds
MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Bookmarks