This can be done.
First one should trap application events. To do this, a class module with Application reference and DocumentBeforeSave event definition should be added and initialized in Normal.dot (or user template), see help file "Using Events with the Application Object".
Next, having that Doc (argument in the event procedure) is the document to be saved you can check value, for instance title: Doc.BuiltInDocumentProperties("Title".
If something is missing, set Cancel=True and promt for filling document info. I found Dialogs(wdDialogFileSummaryInfo).Show command to display a part of built-in document properties.
Hi Muzzy,
In the Normal.dot project you have ThisDocument object. You need also a standard module and a class module. select Normal project and add them.
Name the class module clsApp. Put the code (asks once to add title):
[tt]Public WithEvents App As Word.Application
Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
If Len(Doc.BuiltInDocumentProperties("Title") < 1 Then
MsgBox "Please enter the document title"
Dialogs(wdDialogFileSummaryInfo).Show
If Len(Doc.BuiltInDocumentProperties("Title") < 1 Then
Cancel = True
End If
End If
End Sub[/tt]
In the standard module (initializing application events, clsApp is from your class module name):
[tt]Public X As New clsApp
Sub InitApp()
Set X.App = Word.Application
End Sub[/tt]
In ThisDocument module (automatically call initializing procedure when document created with Normal template is closed):
[tt]Private Sub Document_Close()
Call InitApp
End Sub[/tt]
This is a raw code, event handling is to be polished (it acts also on template should be excluded) but you can polish it.
The above code has a gap - is mot initialized while saving first document (saturday night...).
The below (full, no code in ThisDocument) is simpler and complete, should also be in the Normal project.
Standard module, must be named "AutoExec", procedure must be named "Main" (or only procedure named "AutoExec":
[tt]Dim X As New clsApp
Sub Main()
Set X.app = Word.Application
End Sub[/tt]
Class module, named "clsApp" (same as type in declaration above):
[tt]Public WithEvents app As Application
Private Sub App_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As Boolean, Cancel As Boolean)
If Len(Doc.BuiltInDocumentProperties("Title") < 1 Then
MsgBox "Please enter the document title"
Dialogs(wdDialogFileSummaryInfo).Show
If Len(Doc.BuiltInDocumentProperties("Title") < 1 Then
Cancel = True
End If
End If
End Sub[/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.