Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Word Properties Box

Status
Not open for further replies.

Muzzy

Programmer
Dec 14, 2001
68
GB
Dear All,

Is there any way to get the 'Properties' box from the 'File Menu' to appear and force the user to enter data about the New Document when it is saved?

Cheers

Muzzy
 
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.

combo
 
Cheers for your help,

Do you possibly have any code that already does this?

Cheers

Muzzy
 
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(&quot;Title&quot;)) < 1 Then
MsgBox &quot;Please enter the document title&quot;
Dialogs(wdDialogFileSummaryInfo).Show
If Len(Doc.BuiltInDocumentProperties(&quot;Title&quot;)) < 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.

combo
 
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 &quot;AutoExec&quot;, procedure must be named &quot;Main&quot; (or only procedure named &quot;AutoExec&quot;):
[tt]Dim X As New clsApp
Sub Main()
Set X.app = Word.Application
End Sub[/tt]

Class module, named &quot;clsApp&quot; (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(&quot;Title&quot;)) < 1 Then
MsgBox &quot;Please enter the document title&quot;
Dialogs(wdDialogFileSummaryInfo).Show
If Len(Doc.BuiltInDocumentProperties(&quot;Title&quot;)) < 1 Then
Cancel = True
End If
End If
End Sub[/tt]

combo


 
Cheers combo, I shal give it a go.

Muzzy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top