PDA

Click to See Complete Forum and Search --> : VB app doesn't release control of Excel.


Kraig K
Nov 30th, 2001, 02:26 PM
I wrote a VB app that reads data from the COM ports and puts it into an array. Then it dumps the data to excel. When I'm done and want to view the data, I double-click the file and Excel doesn't fully launch. If I close my program, then it works. No matter what I try, unless my VB app is closed, any of the files that were created by my app won't load. Here's the parts of my code that have references to creating an Excel object.


Dim objExcel As New Excel.Application
Dim objBook As New Excel.Workbook

dlgCommon.DialogTitle = "Save Data to File"
dlgCommon.Filter = "Excel Files(*.xls)|*.xls"
dlgCommon.ShowSave
Filename = dlgCommon.Filename
Set objBook = objExcel.Workbooks.Add
objExcel.Cells(1, 1) = "Force"
objExcel.Cells(2, 1) = "(" & lblUnits.Caption & ")"
objExcel.Cells(1, 3) = Date
objExcel.Range("C:C").ColumnWidth = 9.5
For i = 1 To Index
objExcel.Cells(i + 3, 1) = DataArray(i)
Next i


What do I have to add so I don't have to close my app first to view my data? The only thing I have in the Form_Unload is:
objExcel.Quit

Which doesn't seem to make a difference.

Scott Penner
Nov 30th, 2001, 04:22 PM
You might try killing the reference to the application from VB.

That is set ObjBook and ObjExcel = nothing.

That should work...

alex_read
Dec 3rd, 2001, 05:16 AM
Set objBook = objExcel.Workbooks.Add
objExcel.Cells(1, 1) = "Force"
objExcel.Cells(2, 1) = "(" & lblUnits.Caption & ")"
objExcel.Cells(1, 3) = Date
objExcel.Range("C:C").ColumnWidth = 9.5

For i = 1 To Index
objExcel.Cells(i + 3, 1) = DataArray(i)
Next i

objExcel.Workbooks(1).Save
objExcel.Quit
Set objExcel = nothing
You might just wanna look up the WITH statement also ;)

Kraig K
Dec 3rd, 2001, 08:17 AM
I added the Set objExcel = Nothing
That took care of it, Thanks!

I was looking into that b4 but I must not have had it right.