Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Release Excell object and component from memory

Status
Not open for further replies.

basicyen

IS-IT--Management
Oct 4, 2002
15
US
Guys...I am writting application in VB to create an Excell spread sheet. User has the option of submit button to begin processing and exit button to close the VB application.

I have a dillema which After the process of generating the Excel document completed and saved with all ActiveX components are set to Nothing, and as the user bring up the excel document to view, the Excell screen window "graphic" came out spotty and trashy.
This happened while the VB "Form" application is still on session, meaning user has not select the exit button. User should be able to resubmit in case the Excel data is wrong.

However,only and only if the VB application is closed entirely by pressing the exit button which to unload the form application. And then proceed to open the Excel document, the excell window displays in normal mode.

I don't know where the problem is, my dilema seems to point that some of the Excel components are still active even though the file has been close and saved and all the components are set to Nothing. Therefore it created a conflict when user mannualy open any Excel Documents to view.

How can I release the Excel object completely from the memory when I am completing generating and saving it.??

Thanks
Yan




 


This is what we do so the user can leave the generated exel doc open but close out the exel resources..

Code:
objExcel.Visible = True
Set objExcel = Nothing
Set gwb = Nothing
Set gws = Nothing

Here is the code to set up the excel doc..
Code:
Private Sub setup_print(Optional fname As String, Optional norst As Boolean)
Dim gstrPath As String

    If IsNull(norst) Then
        norst = False
    End If
    
    Screen.MousePointer = vbHourglass

    Set objExcel = New Excel.Application

    If Len(fname) > 0 Then
     'This is to get a excel Template..
      gstrPath = DLOOKUP("Document_Path", "tbl_Environment_ref")
        objExcel.Workbooks.Add gstrPath & fname
    Else
        objExcel.Workbooks.Add
    End If
    
    objExcel.Visible = True
    
    Set gwb = objExcel.ActiveWorkbook
    Set gws = gwb.Worksheets(1)
    
    If Not norst Then
        Set grst = New ADODB.Recordset
    End If

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top