Solved

VB.NET 2003 Excel Interop call hangs when repeated

Posted on 2007-03-30
7
493 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

705 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

16 Experts available now in Live!

Get 1:1 Help Now