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.CustomDocumentPrope rties and checking that there are properties in there before i enter the If statements.
Dim objProps As Object
Try
objProps = actDoc.CustomDocumentPrope rties
'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("E ventTitle" )) Then
objProps.Add(Name:="EventT itle", Value:=strTitle) ' Type:=Office.MsoDocPropert ies.msoPro pertyTypeS tring, LinkToContent:=False,
'elseif name exists and value doesn't
ElseIf Not IsNothing(objProps.Item("E ventTitle" ).Name) And IsNothing(objProps.Item("E ventTitle" ).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("P lantName") ) Then
objProps.Add(Name:="PlantN ame", Value:=strPlant)
ElseIf Not IsNothing(objProps.Item("P lantName") .Name) And IsNothing(objProps.Item("P lantName") .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?
Dim objProps As Object
Try
objProps = actDoc.CustomDocumentPrope
'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("E
objProps.Add(Name:="EventT
'elseif name exists and value doesn't
ElseIf Not IsNothing(objProps.Item("E
objProps.Item("EventTitle"
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,
If IsNothing(objProps.Item("P
objProps.Add(Name:="PlantN
ElseIf Not IsNothing(objProps.Item("P
objProps.Item("PlantName")
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.