I found a way to determine if a save event was called by code or by a user.
However, I do not understand exactly why this works or if it will cause any
problems. This code works on Win98 and 2k with Excel 97. Can anyone
explain - please.
The following code is part of an add-in that prompts the user for the
document properties each time a workbook is saved.
Private Sub Appl_WorkbookBeforeSave(ByVal Wb As Workbook, ByVal SaveAsUI As
Boolean, Cancel As Boolean)
On Error Resume Next
''' Initialize the ShowInst variable
ShowInst = Workbooks("Document Properties
Prompt.xla").CustomDocumentProperties("ShowInst"). Value
''' Fill in the Document Properties that are blank with Instructions
If ActiveWorkbook.BuiltinDocumentProperties("Title"). Value = "" Then
ActiveWorkbook.BuiltinDocumentProperties("Title"). Value = "Enter the
File Name"
End If
If ActiveWorkbook.BuiltinDocumentProperties("Subject" ).Value = "" Then
ActiveWorkbook.BuiltinDocumentProperties("Subject" ).Value = "Enter a
brief Description of the File"
End If
If ActiveWorkbook.BuiltinDocumentProperties("Author") .Value = "" Then
ActiveWorkbook.BuiltinDocumentProperties("Author") .Value = "Enter
the 8 digit User ID of the person responsible for the File"
End If
If ActiveWorkbook.BuiltinDocumentProperties("Comments ").Value = "" Then
ActiveWorkbook.BuiltinDocumentProperties("Comments ").Value = "Enter
a Date in ""YY/MM/DD"" format followed by a brief description of changes
made followed by a simicolon (;) then press enter"
End If
''' Check to see if the InstForm should be shown
'''=============================================== ==========================
====
''' I am not sure why this works or what the xlDialogEditionOptions
''' dialog is supposed to do. However, it will return TRUE or FALSE
''' based on whether it should show or not. Like the xlDialogProperties
''' dialog, it will not show when the save was called from code returning
''' FALSE. It will not show when the save was called by a user either, but
''' it will return TRUE just like the xlDialogProperties does when it shows.
''' So xlDialogEditionOptions will work as a test for wether or not the
''' save event was called from code or by a user.
'''=============================================== ==========================
=====
If Application.Dialogs(xlDialogEditionOptions).Show Then
If ShowInst = True Then
InstForm.Show
End If
End If
''' Show the Properties dialog
Application.Dialogs(xlDialogProperties).Show
End Sub
Can anyone tell me what the xlDialogEditionOptions dialog is for or what it
does or if this will cause any problems?
I need to distribute this add-in company wide and I want to make sure it
won't cause problems. I have tested it on about a dozen machines so far with
out any problems.
David Sedberry