?
Solved

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

Posted on 2007-03-28
3
Medium Priority
?
1,513 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
[X]
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
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
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 …

777 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