• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

Office Interop - from a windows form how to reestablish connection to a previously started Office application

After restart of a Windows Forms application (crashed due to severe error) how can I reestablish connection to a previously initiated Excel instance which is still existing and
contains important data for the restarted forms application ?

I have a VB.net based Windows forms application which is using Excel in the background for calculations.

I am starting Excel with
    Public Excel_App As Microsoft.Office.Interop.Excel.Application
    Public Excel_WB As Microsoft.Office.Interop.Excel.Workbook
    Public Excel_WS As Microsoft.Office.Interop.Excel.Worksheet
    Dim Filepath As String

    Excel_App = New Microsoft.Office.Interop.Excel.Application
    Excel_App.WindowState = Microsoft.Office.Interop.Excel.XlWindowState.xlNormal
    Excel_App.Visible = False
    Excel_App.DisplayStatusBar = False
   
    Filepath ="C:\Filename.xls"
    Excel_WB = Excel_App.Workbooks.Open(FilePath)
    Excel_WS = Excel_WB.Worksheets("Data")

    <Processing of data on the Excel sheet>

When the foems application is restatred after a crash the code is creating a new instance of Excel which then opens the same file, however this time in read only mode (because the previous instance is still alive).

I like to identify such a case and reestablish connection to the previous Excel instance instead of creating a new one.

I will appreciate any hint on how to do this.
0
Phyllax
Asked:
Phyllax
  • 2
1 Solution
 
Corey ScheichDeveloperCommented:
Excel_App = getobject("Excel.application")
0
 
Corey ScheichDeveloperCommented:
Here is a pretty good full example. That will create a new instance if one isn't available
http://msdn.microsoft.com/en-us/library/e9waz863(v=vs.71).aspx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now