Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Outlook Free & Paid Tools
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

856 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