How doc properties created in one file be available in all docs

  • Thread starter Document properties
  • Start date
D

Document properties

I need to insert fields in a word document. All required doc properties was
created in File>Properties>Custom. This was inserted into the document using
Insert>Field option. Now i need this set of doc properties to be available in
all the files that i edit or create new. I tried creating this in Normal.dot,
but still it does not show if a new document is opened.
 
L

Lene Fredborg

Custom document properties in Normal.dot do not seem to be inherited by
documents based on Normal.dot.

On the other hand, if you add your custom document properties to another
template, new documents based on that template are “born†with the set of
properties. But the properties will not be added to existing documents even
if you attach the documents to that template.

Therefore, I think the best solution for you is to add a macro to your
Normal.dot (or to a global template). Below is some macro code you can use -
you can assign a keyboard shortcut to the macro and/or add it to a toolbar
button:

Sub CreateProperties()

Dim oProp As DocumentProperty
Dim oPropName_Array As Variant
Dim oPropValue_array As Variant
Dim bPropExists As Boolean
Dim n As Long

'array of all property names - replace by your names
'add or remove items as needed
oPropName_Array = Array("Prop1", _
"Prop2", _
"Prop3", _
"Prop4")
'array of corresponding property values - replace by your values
oPropValue_array = Array("ValueOfProp1", _
"ValueOfProp2", _
"ValueOfProp3", _
"ValueOfProp4")

bPropExists = False 'set to true if property is already found

'run through all the property names
For n = LBound(oPropName_Array) To UBound(oPropName_Array)
'check whether property is already found
For Each oProp In ActiveDocument.CustomDocumentProperties
If oProp.Name = oPropName_Array(n) Then
bPropExists = True
Exit For 'no need to check more
End If
Next oProp

'add property if not already found
If bPropExists = False Then
With ActiveDocument
.CustomDocumentProperties.Add _
Name:=oPropName_Array(n), _
LinkToContent:=False, _
Value:=oPropValue_array(n), _
Type:=msoPropertyTypeString
'Type must be changed if the properties are not strings
End With
End If
Next n

End Sub
--------------------
If you want the macro to run automatically each time you create a new
document or open an existing document, you could also add the following
macros to Normal.dot or the global template:

Sub AutoNew()
'create properties
CreateProperties 'run Sub
End Sub

Sub AutoOpen()
'create properties
CreateProperties 'run Sub
End Sub

AutoNew will run each time you create a new document. AutoOpen will run each
time you open an existing document (however, see the Microsoft Visual Basic
Help on “Auto Macros†for details about the scope of auto macros). And be
careful – do not add such auto macros unless you really want the properties
to be added to *all* your documents.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top