|
-
Mar 14th, 2006, 01:26 PM
#1
Thread Starter
New Member
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:
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
-
Mar 14th, 2006, 04:23 PM
#2
Addicted Member
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:
Application.ScreenUpdating = False
and at the end
VB Code:
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|