Results 1 to 2 of 2

Thread: Excel slow to load

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2006
    Posts
    5

    Question Excel slow to load

    Hello,

    I have developed an application using a MDI form and when the form loads, I load an instance of Excel using the class module below. During the life of the application I load some data to the file File1 and then I print it. The first time that use the application, Excel did load very fast but now it takes almost 40 second to load and 20 second to print my File1. I'm new to automation and vb and I don't know what else to do to improve the speed of excel.
    Any suggestions?
    Thank you.
    Chris.

    Class module
    VB Code:
    1. Private m_oExcel As Excel.Application
    2. Private m_oWorkbook As Excel.Workbook
    3. Private m_oWorksheet As Excel.Worksheet
    4. Private m_bReadyToPrint As Boolean
    5.  
    6. Private Sub Class_Initialize()
    7.  Set m_oExcel = New Excel.Application
    8.  m_strPath = App.Path & "\File1.xls"
    9.  Set m_oWorkbook = m_oExcel.Workbooks.Add(Template:=m_strPath)
    10.  Set m_oWorksheet = m_oWorkbook.Sheets(1)
    11.  m_bReadyToPrint = False
    12. End Sub
    13.  
    14. Private Sub Class_Terminate()
    15.  m_oExcel.ActiveWorkbook.Close False
    16.  m_oExcel.Quit
    17.  Set m_oExcel = Nothing
    18.  Set m_oWorkbook = Nothing
    19.  Set m_oWorksheet = Nothing
    20. End Sub
    21.  
    22. Public Sub CreateReport(mstrArg As String)
    23. On Error GoTo Err
    24.  m_oExcel.Run m_oWorksheet.CodeName & ".DefineVars", mstrArg
    25.  m_oExcel.Run (m_oWorksheet.CodeName & "." & "runExcelReport")
    26.  m_bReadyToPrint = True
    27.  Exit Sub
    28.  
    29. Err:
    30.  m_bReadyToPrint = False
    31. End Sub
    32.  
    33. Public Sub PrintReport(frm As Form, objCmmDgl As CommonDialog)
    34.  If m_bReadyToPrint Then
    35.   With objCmmDgl
    36.    .PrinterDefault = True
    37.    .ShowPrinter
    38.   End With
    39.   m_oWorksheet.PrintOut 1, 1, 1, False
    40.  
    41.  Else
    42.   MessageBox frm.hWnd, "Report was not create correctly. Cannot print report!" & vbCrLf & Err.Description, "Report information", vbOKOnly
    43.  End If
    44.  
    45. End Sub

  2. #2
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Re: Excel slow to load

    I had this kind of problem last week.
    I used the magic trick to solve my problem.

    Before using the magic trick write at the beginning of the procedure that load data
    VB Code:
    1. Application.ScreenUpdating = False

    and at the end
    VB Code:
    1. Application.ScreenUpdating = True


    Want to know what is the magic trick?



    1- Save all your stuff.
    2- Click START on bottom left.
    3- Select SHUT DOWN.
    4- Select RESTART.

    That' it...

    Do know why but my app work fine the first time I used procedure using a loop and the next time I tried it, it took forever to accomplish. I restarted my computer and it worked fine.

    Setting applica
    Last edited by billhuard; Mar 14th, 2006 at 04:28 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width