ghostlegend
ghostlegend

Reputation: 572

Do something when workbook gets closed

How can I do this in VBA?

    if (thisWorkbook.close=true) then 
           'do something (send email)
           'and then close the workbook
    end if

Before closing my file, I want to send an email.

Upvotes: 0

Views: 1641

Answers (1)

Use the Workbook_BeforeClose event. In the ThisWorkbook module, add this:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
    'do something (send email)
End Sub

You can even have this code inserted automatically like this:

enter image description here

and then this:

enter image description here

In that listbox you will see all the other available Workbook events.

Upvotes: 3

Related Questions