Solved

VBA Word 2003 - How do you add and retrieve custom doc properties

Posted on 2007-03-28
3
1,503 Views
Last Modified: 2012-06-21
Hello,

I have a word template that has a dialog box attached in which the user enters information to generate the document.  I would like to take the text field info and attach it to the document properties.  Later, I want the user to be able to run a different macro -- which will pull that document property information into the new macros dialog box.  (Trying to avoid the user having to enter the same information twice.)

I'm open to any other suggestions for storing the data if doc properties is not the way to go.. Either way, can you tell me how to do this?

Thank you so much!  ~JTG
0
Comment
Question by:jtaylerg
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 500 total points
ID: 18834580
Hi,

If you want the data to be available after closing the file then from my experience Document Properties will do the job.
To read the custom property:

If CustPropExists("Any_Name_string_a") = True Then
' i.e. it exists so upload it
    your_form_name.your_textbox_name = ActiveDocument.CustomDocumentProperties("Any_Name_string_a").Value
else
' Either initialise the value if wanted
    With ActiveDocument.CustomDocumentProperties
        .Add Name:="Any_Name_string_a", _
        LinkToContent:=False, _
        Type:=msoPropertyTypeString, _
        Value:="a string of your choosing as the value of Any_Name_string_a"
    End With
' and/or do anything you want to do if it doesn't exist
End If

' To set your data into the custom property then the above can be used of course as in the first option of the else clause.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 18834652
The custpropexists function is defined as:

Function CustPropExists(str_Property_Name As String) As Boolean
    Dim doc_Property As DocumentProperty
    CustPropExists = False
    For Each doc_Property In ActiveDocument.CustomDocumentProperties
        If LCase(doc_Property.Name) = LCase(str_Property_Name) Then
            CustPropExists = True
            Exit For
        End If
    Next doc_Property
End Function
0
 

Author Comment

by:jtaylerg
ID: 18835639
Thanks Chris,

I need to play with it some more -- but I think it's working thus far.

Have a great week -- JTG
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
The blinking Office button 4 38
How do I disable Enable background repagination in MS Word 2007? 2 49
How to open a ZIP file. 6 40
Microsoft Edge, Outlook OWA 7 43
No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
My experience with Windows 10 over a one year period and suggestions for smooth operation
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now