Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Document properties - 28 Nov 2006 14:50 GMT
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.
Lene Fredborg - 28 Nov 2006 21:13 GMT
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.

Signature

Regards
Lene Fredborg

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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.