|
-
Jul 28th, 1999, 06:56 PM
#1
Thread Starter
Junior Member
I am having what seems to be a very simple problem, but I can't get it working. I finally figured out how to create an Excel 7.0 file in VB 6. Now the only problem I have is that after I create the file, save it and quit the file, it doesn't go away. So when I try to access it later, I can't because it's already open. What do I do?
-
Jul 28th, 1999, 09:38 PM
#2
New Member
Could you please post the code you're using to create the workbook? It could be that you're not destroying the object variables before closing, or even that you're not destroying them in the right order. A code sample would help a lot.
thanks
-
Aug 1st, 1999, 09:46 PM
#3
Thread Starter
Junior Member
OK, here is some of the code.
On Error GoTo ErrHandler
If msDBType = qsEXCEL_7_0 Then
Set MyExcel = New Excel.Application
MyExcel.Workbooks.Open msDBName
For i = 1 To MyExcel.Worksheets.Count
If UCase$(MyExcel.Worksheets(i).Name) = UCase$(msDBTable) Then
Exit For
End If
Next i
With MyExcel.Worksheets(i)
For j = 1 To mnNumDims + mnNumNLabels + mnNumTLabels + mnNumULabels
sFieldName = Trim$(MyExcel.Worksheets(i).Cells(1, j))
lstDbLabels.AddItem UCase$(sFieldName)
lstDbLabels.ListIndex = j - 1
sDBString = sDBString & "," & sFieldName
nDBCount = nDBCount + 1
DoEvents
Next j
End With
MyExcel.ActiveWorkbook.Close False
MyExcel.Quit
else
'Some other code
end if
This is in the load event of one of my forms.
-
Aug 1st, 1999, 09:59 PM
#4
Thread Starter
Junior Member
Sorry, I forgot to tell you that this form is called from another form.
-
Aug 1st, 1999, 09:59 PM
#5
Thread Starter
Junior Member
Sorry, I forgot to tell you that this form is called from another form.
-
Aug 1st, 1999, 10:00 PM
#6
Thread Starter
Junior Member
Sorry, I forgot to tell you that this form is called from another form.
-
Aug 3rd, 1999, 02:30 AM
#7
New Member
I think you want a 'Set MyExcel=Nothing' in there after you quit excel.
-
Aug 3rd, 1999, 03:43 PM
#8
Thread Starter
Junior Member
I actually thought of that after I wrote that message, but that also didn't work.
-
Aug 3rd, 1999, 04:02 PM
#9
Lively Member
There are a number of Knowledge Base articles about the variety of ways Excel automation can get screwed up as far as releasing an object reference or not. I had a similar problem where the user could close Excel but it will still appear in the Task list. The way I solved it was to use the
GetObject method to open my Excel object. If that fails (or if you always want to open a new Excel session) then use CreateObject instead of New Excel.Application. I have no idea why this should make a difference, but it worked for me. Still, I recommend you check out the Knowledge Base.
Hope this helps.
Bash
-
Aug 3rd, 1999, 05:00 PM
#10
Member
ChrisCole,
Have you tried the following 2 lines
MyExcel.Application.Quit
Set MyExcel = Nothing
Hope this helps some...
-
Aug 5th, 1999, 05:16 PM
#11
Thread Starter
Junior Member
Nothing has worked yet!! I can't find anything on this problem. I tried the CreateObject and OpenObject, but I got an error message saying something about ActiveX not being able to open or create and object.
-
Aug 5th, 1999, 06:15 PM
#12
New Member
Did you add a reference to excel? Just wondering..
-
Aug 5th, 1999, 07:07 PM
#13
Thread Starter
Junior Member
Yes I did. I have everything else working. If I try to close the Workbook, Excel brings up a message saying the file exists, would you like to overwrite. If I just click the Yes button, it's fine, but this program is supposed to have almost no interaction with the user.
As for the Excel not going away, when I do the Excel.quit and set excel = nothing, it doesn't get rid of one of the Excels.
-
Aug 6th, 1999, 12:20 AM
#14
Frenzied Member
Use the following in your Excel close event (you send):
SaveChanges:=False
For example (MyExcel defined as an object):
MyExcel.Close SaveChanges:=False
Then, reopen the workbook. I'd use this to solve my post (in the general forum) except I get the stinkin virus warning message every time (and, yes, I know how to turn it off but can't/won't).
-
Aug 6th, 1999, 06:24 AM
#15
New Member
this is the code I use to export to a excel file..
Private Sub mnuexport_Click()
Dim d As Database
Dim r As Recordset
Dim q As QueryTable
Set d = OpenDatabase(App.Path & "\Peopledb.mdb")
Set r = d.OpenRecordset("SELECT * FROM Info")
Dim x As New Excel.Application
x.Application.DisplayAlerts = False
x.Visible = False
Dim w As Worksheet
x.Workbooks.Add
Set w = x.Worksheets(1)
Set q = w.QueryTables.Add(r, w.Range("A1"))
q.Refresh (True)
x.Workbooks.Application.SaveWorkspace "c:\Personal.xls"
MsgBox "Saved Production to EXCEL97.", vbInformation, "Personal.xls Saved!!"
'x.SaveChanges = False
x.Quit
Set d = Nothing
Set r = Nothing
On Error GoTo exit2
exit2:
Exit Sub
MsgBox "WE GOOFED UP!!!!", vbInformation, "Personal.xls Not-Saved!!"
End Sub
When the user hits cancel ont he saveas screen , it comes up with a 1004 error, how can i trap this litte pain??
-
Aug 9th, 1999, 04:09 AM
#16
New Member
You are welcome. But my 1004 error is still buggin me, can you happen to find out how to trap it..? When the saveas thing comes up & I hit cancel it says object not created 1004 error..
------------------
~\*/~ Thank you....
-
Aug 9th, 1999, 04:21 AM
#17
Frenzied Member
Well, I don't use the construct
Dim x As New Excel.Application
So i don't know if VB can trap the error but I'd try:
if Err.Number = 1004 then
err.clear
exit sub
end if
'put the above on the line following : x.Workbooks.Application.SaveWorkspace "c:\Personal.xls"
[This message has been edited by JHausmann (edited 08-09-1999).]
-
Aug 9th, 1999, 04:41 AM
#18
New Member
I tried it above & below & both.. No go.. Guess this is a untrappable error.. Fart..
------------------
~\*/~ Thank you....
-
Aug 9th, 1999, 11:05 AM
#19
Thread Starter
Junior Member
Finally, it WORKS!!! Thank you so much!!
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
|