OnSave Property

Applies To

Workbook Object.

Description

Returns or sets the name of a Visual Basic procedure to run after the user invokes either the Save or Save As command but before the workbook is actually saved. This property is available only in Microsoft Excel for Windows 95. Read-write.

Remarks

The procedure you specify must take one Boolean argument.

Only Visual Basic procedures are supported. Microsoft Excel 4.0 Macro Language procedures aren't supported.

The value of this property isn't saved with the workbook; it must be reset each time the workbook is opened.

This event isn't called if the workbook is saved when a macro or mail command runs, when an embedded workbook is updated, or when an unsaved workbook is saved as part of a workbook that's being closed.

Example

This example displays a message box after the user invokes either the Save or Save As command but before the workbook is saved.


' Specifies the procedure to run when the workbook is saved
Sub SetSaveEvent()
    ActiveWorkbook.OnSave = "SaveProcedure"
End Sub

Sub SaveProcedure(s As Boolean)
    MsgBox "Excel will now save your work"
End Sub