checking empty CustomDocumentProperties in MS Word

Posted on 2004-10-27
Last Modified: 2008-02-01
I am trying to edit the CustomDocumentProperties in MS Word. I have custom properties with a name and value already in CustomDocumentProperties, however, i want to check for an empty value under the 'Name' section. Looking at the code below, i am creating the actDoc.CustomDocumentProperties and checking that there are properties in there before i enter the If statements.

Dim objProps As Object

            objProps = actDoc.CustomDocumentProperties

            'covers empty properties
            'if property values are present in word document, do the following...
            If objProps.Count > 0 Then

'If the first property in CustomDocumentProperties exists, this first block of code is passed

                'if name doesn't exist, nor will value, so add both values
                If IsNothing(objProps.Item("EventTitle")) Then
                    objProps.Add(Name:="EventTitle", Value:=strTitle) ' Type:=Office.MsoDocProperties.msoPropertyTypeString, LinkToContent:=False,
                    'elseif name exists and value doesn't
                ElseIf Not IsNothing(objProps.Item("EventTitle").Name) And IsNothing(objProps.Item("EventTitle").Value) Then
                    objProps.Item("EventTitle").Value = strTitle
                    'both exist so do nothing
                End If

'however, if i have no more properties then the first If statment should be working, and adding the corresponding property values into CustomDocumentProperties, but
'this line of code is skipped and a "false parameter" error appears. I know the reason for this error is because it is checking for "PlantName" as the property name inside
'CustomDocumentProperties, which doesn't exist.

                If IsNothing(objProps.Item("PlantName")) Then
                    objProps.Add(Name:="PlantName", Value:=strPlant)
                ElseIf Not IsNothing(objProps.Item("PlantName").Name) And IsNothing(objProps.Item("PlantName").Value) Then
                    objProps.Item("PlantName").Value = strPlant
                End If

How do i check for a null property existence using only the built in methods of my objProps Object?
Question by:dev-ngps7
    1 Comment
    LVL 8

    Accepted Solution

    Write this code between a Try - Catch

       'If this code fails, it means PlantName is Null
       dim strTest as Object
       strTest = objProps.Item("PlantName").Value
       'If an error occurs PlantName will be added
       objProps.Add(Name:="PlantName", Value:=strPlant)
    end try

    If  IsNothing(objProps.Item("PlantName").Value) Then
       objProps.Item("PlantName").Value = strPlant
    End If

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    933 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

    18 Experts available now in Live!

    Get 1:1 Help Now