Solved

VB.NET 2003 Excel Interop call hangs when repeated

Posted on 2007-03-30
7
507 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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 500 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now