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

Posted on 2005-04-18
Last Modified: 2012-06-21
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

Question by:jtaylerg
    LVL 76

    Accepted Solution

    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

    Author Comment

    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!



    Author Comment

    Thanks for the help.  I just rewrote the sub to call the function.

    Have a great day!

    LVL 76

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
    Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
    Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…
    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 …

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now