Accessing workbook properties

Excel's File ^ Properties command displays a dialog box that contains information about the active workbook. You can access the properties from VBA. The following procedure, for example, displays the date and time when the active workbook was saved:

Sub LastSaved()

Dim SaveTime As String On Error Resume Next SaveTime = ActiveWorkbook. _

BuiltinDocumentProperties("Last If SaveTime = "" Then

MsgBox ActiveWorkbook.Name &


MsgBox "Saved: " & SaveTime, End If End Sub

If the workbook has not been saved, attempting to access the Last Save Time property will generate an error. The On Error statement causes this error to be

Save Time").Value " has not been saved." , ActiveWorkbook.Name ignored. The If-Then-Else structure checks the value of the SaveTime variable and displays the appropriate message. If this variable is empty, the file was not saved. Figure 11-9 shows an example of this procedure's result.

Figure 11-9: Displaying the date and time when a workbook was saved.

Quite a few other built-in properties are available, but they're not all relevant to Excel. Consult the Help system for a complete list of built-in properties.

Was this article helpful?

0 0

Post a comment