cmdolcet
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?
How can I monitor this application close and if it does get closed I return to my .net application?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ste5an,
I am calling the following from a vb form to open the excel spreadsheet.
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.
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
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.
There is no such thing as closing an Excel Sheet.
Please elaborate this. What kind of application (VSTO, stand-alone)? What has a form inside Excel to do with it?
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).