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