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:
Private m_oExcel As Excel.Application Private m_oWorkbook As Excel.Workbook Private m_oWorksheet As Excel.Worksheet Private m_bReadyToPrint As Boolean Private Sub Class_Initialize() Set m_oExcel = New Excel.Application m_strPath = App.Path & "\File1.xls" Set m_oWorkbook = m_oExcel.Workbooks.Add(Template:=m_strPath) Set m_oWorksheet = m_oWorkbook.Sheets(1) m_bReadyToPrint = False End Sub Private Sub Class_Terminate() m_oExcel.ActiveWorkbook.Close False m_oExcel.Quit Set m_oExcel = Nothing Set m_oWorkbook = Nothing Set m_oWorksheet = Nothing End Sub Public Sub CreateReport(mstrArg As String) On Error GoTo Err m_oExcel.Run m_oWorksheet.CodeName & ".DefineVars", mstrArg m_oExcel.Run (m_oWorksheet.CodeName & "." & "runExcelReport") m_bReadyToPrint = True Exit Sub Err: m_bReadyToPrint = False End Sub Public Sub PrintReport(frm As Form, objCmmDgl As CommonDialog) If m_bReadyToPrint Then With objCmmDgl .PrinterDefault = True .ShowPrinter End With m_oWorksheet.PrintOut 1, 1, 1, False Else MessageBox frm.hWnd, "Report was not create correctly. Cannot print report!" & vbCrLf & Err.Description, "Report information", vbOKOnly End If End Sub




Reply With Quote