在工作簿关闭时执行某些操作

时间:2014-09-11 08:23:18

标签: vba excel-vba excel

如何在VBA中执行此操作?

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

在关闭我的文件之前,我想发送一封电子邮件。

1 个答案:

答案 0 :(得分:3)

使用the Workbook_BeforeClose event。在ThisWorkbook模块中,添加以下内容:

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

您甚至可以自动插入此代码:

enter image description here

然后这个:

enter image description here

在该列表框中,您会看到all the other available Workbook events