Excel opened by program and closed by user

  • Thread starter Thread starter krechet
  • Start date Start date
K

krechet

How can I catch if the USER closes Excel which I opened from the
external application in VB.NET?

Users can open and interact with a spreadsheet, but how can I tell
when
they close Excel?
I need to set my variables (xlApp) to nothing and do other stuff

Thanks!
 
you could use an automatic before_close macro to reset all your
variables, etc..... although i'm not sure if that will work in vb.net.

Private Sub Workbook_BeforeClose (Cancel as Boolean)

.... your code...

End sub

susan
 
In VB, I'd use a With Events

Dim WithEvents XLApp As Excel.Application

Private Sub CommandButton1_Click()
Set XLApp = New Excel.Application
End Sub

Private Sub XLApp_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As
Boolean)
MsgBox "Closing WB: " & Wb.Name
End Sub

However, I would have thought that as your app holds a reference to the
XLApp, the XL instance cannot close, although the user may dimiss the UI.
There is no Excel event like "Excel_BeforeClose"

Is this for an addin ?

NickHK
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top