|
-
Jul 13th, 2006, 04:13 PM
#1
[RESOLVED] Excel process not closing
I have a simple procedure that opens an Excel workbook (Excel 10) and updates it. However even after Closing, Quiting and setting all objects to nothing the Excel process does not shut down - until the VB application is closed.
I was able to replicate the problem with this code which does nothing more than open the book and reference some objects.
VB Code:
Dim objExcel As Excel.Application
Dim objBook As Excel.Workbook
Dim objSheet As Excel.Worksheet
Dim objRange As Range
Set objExcel = New Excel.Application
Set objBook = objExcel.Workbooks.Open("C:\Testing.xls")
Set objSheet = objBook.Worksheets(1)
Set objRange = objSheet.Range(Cells(1, 1), Cells(1, 2))
Set objRange = Nothing
Set objSheet = Nothing
objBook.Close False
Set objBook = Nothing
objExcel.Quit
Set objExcel = Nothing
The Excel process will shutdown if I comment out this line
Set objRange = objSheet.Range(Cells(1, 1), Cells(1, 2))
Something about that Range object is keeping Excel alive. Is there another method I should be using that will release the Range object? Setting it to nothing does not work.
Last edited by brucevde; Jul 13th, 2006 at 04:27 PM.
-
Jul 13th, 2006, 04:21 PM
#2
Re: Excel process not closing
Change your line where you dimension your range object.
VB Code:
'Form:
Dim objRange As Range
'To:
Dim objRange As Exce.Range
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 
-
Jul 13th, 2006, 04:26 PM
#3
Re: Excel process not closing
How would that make a difference?
I did try it though but Excel still won't shut down.
-
Jul 13th, 2006, 04:28 PM
#4
Re: Excel process not closing
Because when you reference just the default object without fully qualifying it with Excel. your creating a secondary reference to Excel. If you close one without explicitly closing the other then it will cause it to hang. So unless your coding in Excel VBA you should never use the default implied objects.
Did you make sure you started out with no hidden Excel.exe processes running?
Is there any macros in your testing.xls file?
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 
-
Jul 13th, 2006, 04:32 PM
#5
Re: Excel process not closing
I hear more about processes hanging with 2002 then anything else so far. The test code works fine for me under 2003. Have you done all the Office Updates and/or a Detect and Repair from the Help menu?
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 
-
Jul 13th, 2006, 04:37 PM
#6
Re: Excel process not closing
I just seen the reference to the default Cells objects. Those should be changed too.
VB Code:
Set objRange = objSheet.Range(Cells(1, 1), Cells(1, 2))
'to
Set objRange = objSheet.Range(objSheet.Cells(1, 1), objSheet.Cells(1, 2)) 'Or such
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 
-
Jul 13th, 2006, 04:38 PM
#7
Re: Excel process not closing
Thanks anyway Rob.
I was able to get the Excel process to shutdown if I used this statement instead.
VB Code:
Set objRange = objSheet.Range(objSheet.Cells(1, 1), objSheet.Cells(1, 2))
'or this
With objSheet
Set objRange = .Range(.Cells(1, 1), .Cells(1, 2))
End With
Not sure why it makes a difference using the Global.Cells method vs the Sheet.Cells method but problem solved.
-
Jul 13th, 2006, 04:41 PM
#8
Re: Excel process not closing
I beat your post by a minute.
Like I said, its the implied reference that basically, for lack of a better explaination, duplicates a secondary Excel instance so to speak. Then by not destroying it it holds the object in memory causing Excel to remain even if your other fully referenced object vars are closed and destroyed.
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 
-
Jul 13th, 2006, 04:47 PM
#9
Re: Excel process not closing
I beat your post by a minute.
Umm.. the phone rang...
I guess these "secondary Excel objects" would be inaccessible from the VB program
I tried this line as well but it did not work
Set objRange = objSheet.Range(objExcel.Cells(1, 1), objExcel.Cells(1, 2))
So bottom line never use any methods listed in the Object Browser under Globals.
-
Jul 13th, 2006, 04:51 PM
#10
Re: Excel process not closing
Yes. But you need to access the .Cells from the sheet object and not the application opbject.
'No
objExcel.Cells(1, 1)
'Yes
objSheet.Cells(1, 1)
You need to multitask like I do then
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
|