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!

VB app using Excel and Excel won't quit

Status
Not open for further replies.

GAORR

Programmer
Nov 22, 2001
48
CA
I have a Vb app that uses Excel to fill in a few cells and print. I am releasing the resources (set to nothing) but Excel continues to run. How do I shut down Excel when done printing. On my computer at home (XP Pro), I can actually seel that Excel is still running (task manager), on my computer at work it doesn't show it as running (task manager), but on both computers if I attempt to open the same form Excel says it is locked or still open.
The printing part works fine.

Any suggestion would be appreciated. Thanks

Below is the code I am using:

Private Sub cmdPrint_Click()

Dim xlsApp As New Excel.Application
Dim wbXls As Excel.Workbook
Dim wsXls As Excel.Worksheet

Screen.MousePointer = 11

Set xlsApp = New Excel.Application
Set wbXls = xlsApp.Workbooks.Open("C:\Documents and Settings\Gerry\GL_Reno_Proj\glinvoice.xls")
Set wsXls = xlsApp.Worksheets(1)

With wsXls
' header
.Cells(2, 11) = txtInvNo.Text
.Cells(4, 11) = lblCustAddress1.Caption
.Cells(6, 11) = txtReferenceNo.Text

' primary customer
.Cells(11, 3) = lblCustFirstName.Caption + " " + lblCustLastName.Caption
.Cells(12, 3) = lblCustAddress1.Caption
.Cells(13, 3) = lblCustCity.Caption
.Cells(14, 6) = lblCustPhone.Caption

' secondary customer
.Cells(11, 9) = lblSeconCustFirstName.Caption + " " + lblSeconCustLastName.Caption
.Cells(12, 9) = lblSeconCustAddress1.Caption
.Cells(13, 9) = lblSeconCustCity.Caption
.Cells(14, 11) = lblSeconCustPhone.Caption

' dollar values
' .Cells(19, 11) = CLng(txtPreTotal.Text)
.Cells(40, 11) = CLng(txtPreTotal.Text)
.Cells(42, 11) = CLng(txtPreTotal.Text) * 0.08
.Cells(45, 11) = CLng(txtPreTotal.Text) * 1.08

' descriptions
.Cells(19, 2) = "description line 1"
.Cells(20, 2) = "description line 2"
.Cells(21, 2) = "description line 3"
.Cells(22, 2) = "description line 4"
.Cells(23, 2) = "description line 5"
.Cells(24, 2) = "description line 6"
.Cells(25, 2) = "description line 7"
.Cells(26, 2) = "description line 8"
.Cells(27, 2) = "description line 9"
.Cells(28, 2) = "description line 10"

End With

xlsApp.Visible = False

wsXls.PrintOut

Screen.MousePointer = 0

Set xlsApp = Nothing
Set wbXls = Nothing
Set wsXls = Nothing
End Sub
 
> Instead of

Use it as well so that variable no longer refers to an actual object.
Code:
xlsApp.Quit
Set xlsApp = Nothing


----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top