|
-
Nov 14th, 2006, 11:48 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Can not kill Excel Objects....VB
Hi i am handing Excel file with vb. but even i close the application Excel.exe will be their in Windows Task Manager. so whenevr i run my code, Excel.exe count increses....so at one stage i can not open excel file. since its objects are not closed.
In clode i have clearly closed anf kille dthe objects
like,
myExcel.Close
set myExcel as nothing
set myWorkSheet as nothing
set myWorkBook as nothing
But in task manager i can see Excel.exe
Please reply
-
Nov 15th, 2006, 12:05 AM
#2
Lively Member
Re: Can not kill Excel Objects....VB
You can always use the FindWindow-function and the PostMessage-function to find the wanted application, and then send it a message that it has to close itself. One disadvantage: you'll need the exact caption of this application.
Try this
VB Code:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CLOSE = &H10
Private Sub Form_Load()
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "Calculator")
If winHwnd <> 0 Then
PostMessage winHwnd, WM_CLOSE, 0&, 0&
Else
MsgBox "The Calculator is not open."
End If
End Sub
Thanx to AllAPI
-
Nov 15th, 2006, 12:33 AM
#3
Re: Can not kill Excel Objects....VB
Its bad programming practice to try to terminate a running process or sending the close message to it. Its better to find the offending code and correct it. You should never need to use a workaround to close Excel when you are automating it if its done correctly. 
Its all about disposing of the Excel objects in the proper order in order to prevent the orphaning of the object heirarchy. Also, never use the implicit Excel objects without using an object variable for them. Ex. Range object.
Any sheet or range object variables set to Nothing.
Then .Close any Workbooks.
Then set your workbook(s) = Nothing
Then .Quit your Excel.Application object variable.
Then set it equal to Nothing
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 15th, 2006, 12:46 AM
#4
Thread Starter
Addicted Member
Re: Can not kill Excel Objects....VB
Thank you very much
actually i had one more reference which is not closed...
I made it nothing....
Thanks alot for reply
 Originally Posted by RobDog888
Its bad programming practice to try to terminate a running process or sending the close message to it. Its better to find the offending code and correct it. You should never need to use a workaround to close Excel when you are automating it if its done correctly. 
Its all about disposing of the Excel objects in the proper order in order to prevent the orphaning of the object heirarchy. Also, never use the implicit Excel objects without using an object variable for them. Ex. Range object.
Any sheet or range object variables set to Nothing.
Then .Close any Workbooks.
Then set your workbook(s) = Nothing
Then .Quit your Excel.Application object variable.
Then set it equal to Nothing
-
Nov 15th, 2006, 12:49 AM
#5
Re: [RESOLVED] Can not kill Excel Objects....VB
It was the order and not closing of the workbook just from what I seen in your first post.
Glad to have helped.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
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
|