• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 705
  • Last Modified:

Word 03 - Custom Doc Property - How do you find out if it exists already?

Hi There,

I'm trying to come up with an easy way to distinguish whether or not a user created a document from a firm template or copied it from our old system.

So I decided to add a custom doc property to the new templates.

I need vba code to determine if the custom doc property exists in the active document.  If it does, we move on.  If it doesn't, they get a message that they're not working in a current system file.

Any ideas?

Thanks!  JTG


0
jtaylerg
Asked:
jtaylerg
  • 2
  • 2
1 Solution
 
GrahamSkanCommented:
Function HasProperty() As Boolean
Const MyPropertyName = "MyProp"
Dim cdp As DocumentProperty
For Each cdp In ActiveDocument.CustomDocumentProperties
    If cdp.Name = MyPropertyName Then
        HasProperty = True
        Exit Function
    End If
Next cdp
MsgBox "Not current system file"
End Function
0
 
jtaylergAuthor Commented:
Man You're Fast!!!

Novice:  I'm sorry, I'm not familiar with functions.

I've been writing everything as public and private subs.  Can I use a function within a Sub?

For instance, if they click a button that runs "Public Sub FileSave()"

within that sub can I run the function or does it need to call the function?

Thanks again!

JTG




0
 
jtaylergAuthor Commented:
Thanks for the help.  I just rewrote the sub to call the function.

Have a great day!

JTG
0
 
GrahamSkanCommented:
I don't normally use Functions when a Sub will do. I had intended to write a calling sub, but changed my mind and just wrote the Message box inside the function.

If not HasProperty then
   Msgbox "Not current system File"
End If

Thanks for the grade & I've already had a nice day (It's 21:15 here). But have a good one yourself.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now