Skip to content

Latest commit

 

History

History
56 lines (35 loc) · 1.5 KB

Excel.Application.WorkbookBeforeClose.md

File metadata and controls

56 lines (35 loc) · 1.5 KB
title keywords f1_keywords api_name ms.assetid ms.date ms.localizationpriority
Application.WorkbookBeforeClose event (Excel)
vbaxl10.chm504084
vbaxl10.chm504084
Excel.Application.WorkbookBeforeClose
9c3618ea-0e5e-e4fe-20af-279826bfa7c3
04/05/2019
medium

Application.WorkbookBeforeClose event (Excel)

Occurs immediately before any open workbook closes.

Syntax

expression.WorkbookBeforeClose (Wb, Cancel)

expression A variable that represents an Application object.

Parameters

Name Required/Optional Data type Description
Wb Required Workbook The workbook that's being closed.
Cancel Required Boolean False when the event occurs. If the event procedure sets this argument to True, the workbook doesn't close when the procedure is finished.

Return value

Nothing

Example

This example prompts the user for a yes or no response before closing any workbook.

For more information about how to use event procedures with the Application object, see Using events with the Application object.

Private Sub App_WorkbookBeforeClose(ByVal Wb as Workbook, _ 
 Cancel as Boolean) 
 a = MsgBox("Do you really want to close the workbook?", _ 
 vbYesNo) 
 If a = vbNo Then Cancel = True 
End Sub

[!includeSupport and feedback]