+ Reply to Thread
Results 1 to 10 of 10

How to speed up opening workbooks in excel VBA code

  1. #1
    Registered User
    Join Date
    09-05-2019
    Location
    Egypt
    MS-Off Ver
    Office Professional Plus 2013
    Posts
    9

    How to speed up opening workbooks in excel VBA code

    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
    Attached Files Attached Files
    Last edited by moamen_2019; 09-09-2021 at 08:53 AM.

  2. #2
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,316

    Re: How to speed up opening workbooks in excel VBA code

    Possibly...
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    09-05-2019
    Location
    Egypt
    MS-Off Ver
    Office Professional Plus 2013
    Posts
    9

    Re: How to speed up opening workbooks in excel VBA code

    Unfortunately this did not solve the problem.
    The attached workbook took 26 seconds to open.
    Attached Files Attached Files

  4. #4
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,316

    Re: How to speed up opening workbooks in excel VBA code

    Try disabling calculations...
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-05-2019
    Location
    Egypt
    MS-Off Ver
    Office Professional Plus 2013
    Posts
    9
    Quote Originally Posted by dangelor View Post
    Try disabling calculations...
    Please Login or Register  to view this content.
    Unfortunately I already tried disabling automatic cqlculation but it does not work either.
    Actually it made it worse as the workbook took over 30 seconds to open this time.
    Last edited by moamen_2019; 09-09-2021 at 09:24 AM.

  6. #6
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,316

    Re: How to speed up opening workbooks in excel VBA code

    What time do you get with this...
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    09-05-2019
    Location
    Egypt
    MS-Off Ver
    Office Professional Plus 2013
    Posts
    9
    Quote Originally Posted by dangelor View Post
    What time do you get with this...
    Please Login or Register  to view this content.
    30 seconds

  8. #8
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,316

    Re: How to speed up opening workbooks in excel VBA code

    Try saving the file as an .xlsb file.

  9. #9
    Registered User
    Join Date
    09-05-2019
    Location
    Egypt
    MS-Off Ver
    Office Professional Plus 2013
    Posts
    9
    Quote Originally Posted by dangelor View Post
    Try saving the file as an .xlsb file.
    I did but it did not improve any thing.

  10. #10
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    MS365 V.2406
    Posts
    2,316

    Re: How to speed up opening workbooks in excel VBA code

    It opens in 8 seconds on my i5 laptop. Since you were getting it open in 20 seconds in your original code (post #1), use that.

    Sorry I couldn't help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Speed up Opening of Large Workbooks?
    By atwy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2015, 03:13 AM
  2. Replies: 1
    Last Post: 06-10-2014, 10:54 AM
  3. code for opening all workbooks in a folder on desktop
    By ammartino44 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-21-2014, 04:39 PM
  4. Opening, Closing, and Opening Excel workbooks from MS Project
    By m007schneider in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-04-2013, 03:22 PM
  5. Opening Workbook as new Instance - code affecting other workbooks
    By supes77 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-19-2012, 03:40 AM
  6. Reducing Code For Opening Multiple Workbooks and Selecting A Sheet In Each
    By ColeJones in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-12-2011, 07:17 PM
  7. [SOLVED] Opening and Closing workbooks in code
    By Francis Brown in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-26-2005, 10:15 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1