Solved

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

Posted on 2007-03-28
3
1,501 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

744 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

10 Experts available now in Live!

Get 1:1 Help Now