Link to home
Start Free TrialLog in
Avatar of cmdolcet
cmdolcetFlag for United States of America

asked on

How to monitor an excel sheet closure from .net

I open an excel program from my .net program. The user sends data to the cells and then closes the form inside excel.

How can I monitor this application close and if it does get closed I return to my .net application?
ASKER CERTIFIED SOLUTION
Avatar of Vaughn Bigham
Vaughn Bigham
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
About your subject:
There is no such thing as closing an Excel Sheet.

I open an excel program from my .net program. The user sends data to the cells and then closes the form inside excel.
Please elaborate this. What kind of application (VSTO, stand-alone)? What has a form inside Excel to do with it?

How can I monitor this application close and if it does get closed I return to my .net application?
Monitoring the Excel instance using the Process related PID can work in many scenarios, but it does not monitor closing an Excel workbook. Sometimes closing a workbook does not close the instance and leaves Excel open showing a gray background.
Thus to be sure, you need to poll that instance, whether your workbook is still open (loaded).
Avatar of cmdolcet

ASKER

ste5an,

I am calling the following from a vb form to open the excel spreadsheet.

 Private Sub TmrCheckExcel_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TmrCheckExcel.Tick
        IsProcessRunning(Name)
    End Sub
    Public Function IsProcessRunning(ByVal name As String) As Boolean
        For Each clsProcess As Process In Process.GetProcesses()
            If clsProcess.ProcessName.StartsWith("EXCEL") Then
                Return True
            End If
        Next
        Return False
    End Function

Open in new window


It will open just fine and I can send readings directly to the sheet. I would then like to monitor the close function on the excel sheet.