|
-
Nov 30th, 2001, 03:26 PM
#1
Thread Starter
Addicted Member
VB app doesn't release control of Excel.
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.
Code:
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.
-
Nov 30th, 2001, 05:22 PM
#2
Hyperactive Member
kill the reference
You might try killing the reference to the application from VB.
That is set ObjBook and ObjExcel = nothing.
That should work...
-scott
he he he
-
Dec 3rd, 2001, 06:16 AM
#3
Code:
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
-
Dec 3rd, 2001, 09:17 AM
#4
Thread Starter
Addicted Member
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.
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
|