CustomDocumentProperties

L

LA Lawyer

I want to be able to determine the value of the of the Custom Document
Property which I have named "Signatory" so that I can display that value in
a Message Box (msgbox).

How do I obtain the value of this property using VBA?

Also, is there a simple code to determine whether that Custom Property
actually exists?

I am using Word 2007.
 
D

Doug Robbins - Word MVP

If find it much easier to use DocumentVariables, which can also be displayed
in a document by use of a {DOCVARIABLE varname} field

To set the value of a Document Variable, you would use

ActiveDocument.Variables("varSignature").Value = "somevalue"

To display the value of the variable in a message box

MsgBox ActiveDocument.Variables("varSignature").Value

If the variable does not exist, you will get a 5825 error

On Error GoTo errHandler
MsgBox ActiveDocument.Variables("varSignature").Value

errHandler:
If Err.Number = 5825 Then
MsgBox "A value has not be set for the varSignature variable"
End If



--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
G

Gordon Bentley-Mix on news.microsoft.com

I agree with Doug; document variables have many advantages over custom
document properties - not the least of which is that they're much more
difficult for the user to modify.

However, if you really want to display the value of a custom document
property in a message box, something like the following should work:

MsgBox ActiveDocument.CustomDocumentProperties("Signatory").Value

Note that if the document property doesn't exist, you will get "Run-time
error '5': Invalid procedure call or argument".

BTW, because I use document variables extensively in so many templates, I've
written (with the help of Greg Maxey) a custom function to determine the
existence of a variable - similar to the .Exists method for bookmarks.

Public Function fcnFindVar(VarName As String) As Boolean
Dim myValue As String
fcnFindVar = False
On Error Resume Next
myValue = ActiveDocument.Variables(VarName).Value
'(As Doug said, if the doc var doesn't exist you get 5825 error)
If Err.Number = 0 Then fcnFindVar = True
End Function

I'm sure this could be adapted to work with custom document properties as
well.
--
Cheers!

Gordon Bentley-Mix
Word MVP

Please post all follow-ups to the newsgroup.

Read the original version of this post in the Office Discussion Groups - no
membership required!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top