How can I check to see if a CustomDocumentProperties exists?

L

Leila

For this checking I get below error, please help, thanks
If (ActiveDocument.CustomDocumentProperties("MyProperty")
= False) Then

*err* Invalid procedure call or argument
 
J

Jay Freedman

Leila said:
For this checking I get below error, please help, thanks
If (ActiveDocument.CustomDocumentProperties("MyProperty")
= False) Then

*err* Invalid procedure call or argument

Hi Leila

You need to use the property's .Value member:

If (ActiveDocument.CustomDocumentProperties("MyProperty").Value = False)
Then

The other thing is that if you try to retrieve the value of a doc property
that doesn't exist, you'll get the same error. The way to avoid that is to
loop through all the doc properties like this:

Dim prop As DocumentProperty
For Each prop In ActiveDocument.CustomDocumentProperties
If prop.Name = "MyProperty" Then
If prop.Value = False Then
MsgBox "It's False"
End If
End If
Next prop

The example in the CustomDocumentProperties topic in the help shows another
loop like this.
 

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