Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB.NET 2003 Excel Interop call hangs when repeated

Posted on 2007-03-30
7
Medium Priority
?
541 Views
Last Modified: 2010-05-18
In my VB.NET 2003 application, Excel is spawned using this:
Imports Excel = Microsoft.Office.Interop.Excel
: which is assigned outside of the formMain class.

This works fine the first time Excel is called.  But as soon as I try to run the data display subroutine (which called Excel the first time) the program freezes.  This happens even if Excel isn't going to be used in that subroutine, which is what's really confusing.  The subroutine starts but does not appear to process even a single line of code before locking up.

So examples:
1) Run data display with "tables" option instead of "excel" - works fine
2) Run with "tables" - works fine
3) Run with "excel" - works fine
4) Run with "excel" - hangs

1) Run with "excel" - works fine
2) Run with "excel" - hangs

1) Run with "excel" - works fine
2) Run with "tables" - hangs

This is very, very confusing to me.  Any help?

0
Comment
Question by:richdiesal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 2

Expert Comment

by:vjc2003
ID: 18834505
looks a bit confusing too.
are you properly initialising and closing excel in the subroutine??

check in process tab of TaskManager if u are exiting the Excel application.
Else when u initialise it again,program will freeze.

Also are you initialising excel in some common place?
0
 
LVL 9

Author Comment

by:richdiesal
ID: 18838265
All I have referencing Excel in a common place is outside of everything:
Imports Excel = Microsoft.Office.Interop.Excel

The rest is inside an If clause of a subroutine:
            Dim oXL As New Excel.Application
            If oXL Is Nothing Then Throw (New Exception("Fatal Error: Excel launch failed."))
            Dim oBook As Excel.Workbook
            Dim oSheet As Excel.Worksheet
            'oXL = New Excel.Application
            oBook = oXL.Workbooks.Add()
            oBook = oXL.ActiveWorkbook

..... some Excel parsing here...

            oBook.SaveAs(SaveText.FileName, Excel.XlFileFormat.xlWorkbookNormal)
            oXL.Quit()

            oSheet = Nothing
            oBook = Nothing
            oXL = Nothing


You are right about Excel still being open, but shouldn't oXL.Quit take care of that?  Or is something else wrong here?
0
 
LVL 2

Expert Comment

by:vjc2003
ID: 18841580
Also add this to cleanup part and see if it helps:
oWorkBook.Close(false,null,null)
oXL.Workbooks.Close()

also are'nt u doing some exception handling?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 9

Author Comment

by:richdiesal
ID: 18847332
I added the above - did not help.

And additional exception handling... no.  What you see above is everything I'm doing (as it relates to opening/closing Excel).  I'm really more of a web development in PHP sort of developer (this is a side-project), so this is somewhat uncharted territory for me...
0
 
LVL 2

Accepted Solution

by:
vjc2003 earned 2000 total points
ID: 18849076
Maybe you can try  this:
Kill the excel process manually and see if it is locking up again.

which user account are you using to run the application.
Hope you have given proper permissions to the account.
0
 
LVL 9

Author Comment

by:richdiesal
ID: 18852137
Your prompting me to see if Excel was even open when the problem occurred caused me to investigate options OTHER than Excel, and it turns out there was another error with an infinite While loop that I hadn't noticed before.  All fixed now.  Thanks!
0
 
LVL 2

Expert Comment

by:vjc2003
ID: 18855596
Grt,we were on the wrong lane altogether.
actually,I am a newbie in vb.net too.
Good to know ur problem is solved and thanks for the points.
0

Featured Post

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question