Link to home
Start Free TrialLog in
Avatar of dev-ngps7
dev-ngps7

asked on

checking empty CustomDocumentProperties in MS Word

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

        Try
            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
                Else
                    '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
                Else
                End If


How do i check for a null property existence using only the built in methods of my objProps Object?
ASKER CERTIFIED SOLUTION
Avatar of wguerram
wguerram

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial