Could someone be so helpfull as to look at my small program and see if they can figure out why Excel, and the program itself, resides in the task manager after everything is closed? I'm setting all the objects to nothing (I think) but it still doesn't work. Thank you in advance!
If there is no error then your xlApp only gets Set to Nothing. It wont get .Quit. You need to either .Close or .Quit all your Excel object variables and then after that destroy them by setting them equal to nothing.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
I've created over 50 other vbprojects and never set my startup form to nothing and none of those reside in memory. Any other ideas. I'll try and set both forms to nothing in the startup form unload event.
The form object is not the problem. Excel remains running because just setting it to nothing will not quit the app and destroy it. Do you have any other excel object variables in the Module1.bas?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
The form object is not the problem. Excel remains running because just setting it to nothing will not quit the app and destroy it. Do you have any other excel object variables in the Module1.bas?
I do quit xlApp and then set it to nothing. I also have a chart object which I also set to nothing.
You hide the form but never unload it. Call a routine at the end of you program like such: (Place this in a module and call it from your forms Unload event.
You should make similar changes to the CreateChart sub as I mentioned above.
Also, you should not have object variables declared as "New" anything when they are public (and arguably not at all). You should add a line like this instead when you want the application to open (in form_load and CreateChart):
Code:
Set xlApp = New Excel.Application
And Randem is correct about your splash form, you should be using the amended code as in his first example (or the other if you prefer).
I also noticed that in your formmain's unload event your calling itself to unload again in that procedure creating a circular reference.
VB Code:
Private Sub Form_Unload(Cancel As Integer)
Unload FormSplash
'Unload FormMain 'Circular ref.
Set FormSplash = Nothing
Set FormMain = Nothing
End Sub
Also, switch the event to the Form_QueryUnload event instead. In case your clicking the 'x' at the top right corner to close the app. it will be sure to close and destroy all objects.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
You did not state where you attempted to place the code or anything. The code does work I use it exactly as posted all the time. Did you place this code in a module?
You did not state where you attempted to place the code or anything. The code does work I use it exactly as posted all the time. Did you place this code in a module?
Randem,
I placed your exact code into the Module1.bas and called it from FormMain.QueryUnload. What am I doing wrong?
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)