Solved

VB.NET 2003 Excel Interop call hangs when repeated

Posted on 2007-03-30
7
540 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
Understanding Linux Permissions

Linux for beginners: How to view the permissions associated with files and directories and also how you can change them.

 
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

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 5 hours left to enroll

617 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