WorkBook Deactivate Event

F

faffo1980

Hi all,
The workbook Deactivate event is called when the active workbook is changed
and when the workbook is closed.
The event BeforeClosed for a workbook is called before the event Deactivate.

Is there a way to determine if the WB deactivation is caused by a Close
operation or a change operation?

Thanks

faffo1980
 
J

Jacob Skaria

Copy the below code in 'This Workbook' and try...

Dim blnClose As Boolean
Private Sub Workbook_BeforeClose(Cancel As Boolean)
blnClose = True
End Sub

Private Sub Workbook_Deactivate()
If blnClose Then
MsgBox "Close_Deactivate"
Else
MsgBox "Deactivate"
End If
End Sub

If this post helps click Yes
 
P

Patrick Molloy

in the code page for ThisWorkbook

Option Explicit
Private closeflag As Boolean
Private Sub Workbook_BeforeClose(Cancel As Boolean)
closeflag = True
End Sub
Private Sub Workbook_Deactivate()
If closeflag Then
MsgBox "Closed"
Else
MsgBox "changed"
End If
End Sub
 

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

Top