gmaxey
09-25-2014, 10:13 PM
I have spent the better part of two hours sitting surrounded by clumps of hair and bloody scalp over what appears to be a anomaly with CustomDocumentProperties.
It seems that simply modifying a property value with code isn't enough. You must also have a "quantifiable" change occur in the document.
To demo, create and save a new document and add the following code in a standard module:
Sub AutoOpen()
On Error Resume Next
MsgBox ThisDocument.CustomDocumentProperties("Testing")
On Error GoTo 0
End Sub
Sub CreateModCP()
Dim oCP As DocumentProperty
Dim strText As String
On Error Resume Next
Set oCP = ThisDocument.CustomDocumentProperties("Testing")
strText = InputBox("Enter text value", "Property Value", "text 1, 2, 3, 4")
If Err.Number <> 0 Then
Set oCP = ThisDocument.CustomDocumentProperties.Add(Name:="Testing", LinkToContent:=False, Value:=strText, Type:=msoPropertyTypeString)
Else
oCP.Value = strText
End If
MsgBox "See, the property value is changed to: " & ThisDocument.CustomDocumentProperties("Testing")
' ThisDocument.Variables("Save").Value = "False"
' ThisDocument.Variables("Save").Value = "True"
ThisDocument.Save
End Sub
Run the CreateModCP procedure, use the default inputbox value, then close and reopen the document. When the document opens you should get a msgbox reporting the property value.
Now run the CreateModCP procedure again and change the value in the input box. Close and reopen the document. If you see what I've seen for two hours, the property was not updated.
Now unstet the two lines in the CreateModCP procedure and run it again. Change the value in the input box, close then reopen the file.
You should see the CP now correctly updated.
Is this issue documented anywhere? Do you think this is bug or by design?
Thanks.
It seems that simply modifying a property value with code isn't enough. You must also have a "quantifiable" change occur in the document.
To demo, create and save a new document and add the following code in a standard module:
Sub AutoOpen()
On Error Resume Next
MsgBox ThisDocument.CustomDocumentProperties("Testing")
On Error GoTo 0
End Sub
Sub CreateModCP()
Dim oCP As DocumentProperty
Dim strText As String
On Error Resume Next
Set oCP = ThisDocument.CustomDocumentProperties("Testing")
strText = InputBox("Enter text value", "Property Value", "text 1, 2, 3, 4")
If Err.Number <> 0 Then
Set oCP = ThisDocument.CustomDocumentProperties.Add(Name:="Testing", LinkToContent:=False, Value:=strText, Type:=msoPropertyTypeString)
Else
oCP.Value = strText
End If
MsgBox "See, the property value is changed to: " & ThisDocument.CustomDocumentProperties("Testing")
' ThisDocument.Variables("Save").Value = "False"
' ThisDocument.Variables("Save").Value = "True"
ThisDocument.Save
End Sub
Run the CreateModCP procedure, use the default inputbox value, then close and reopen the document. When the document opens you should get a msgbox reporting the property value.
Now run the CreateModCP procedure again and change the value in the input box. Close and reopen the document. If you see what I've seen for two hours, the property was not updated.
Now unstet the two lines in the CreateModCP procedure and run it again. Change the value in the input box, close then reopen the file.
You should see the CP now correctly updated.
Is this issue documented anywhere? Do you think this is bug or by design?
Thanks.