PDA

View Full Version : ActiveDocument.CustomDocumentProperties



lynnnow
06-24-2014, 11:50 PM
Hi guys,

I'm using Office 2010 and I'm inserting CustomDocumentProperties to use a keyword for prefixing and suffixing text to insert in a document [regular module]


Dim strPrefixTimeStamp As String
Dim strSuffixTimeStamp As String
Dim strProj As String

With ActiveDocument.CustomDocumentProperties
If .Count = 0 Then
strProj = InputBox("Insert type of blank form time stamp" & vbCrLf & vbCrLf & _
"1. (Indiscernible mm:ss)" & vbCrLf & _
"2. -GOTO-mm:ss" & vbCrLf & _
"3. ****mm:ss", "...::: Lynx's Corner :::...")
Select Case Val(strProj)
Case 1
.add Name:="PreFix", LinkToContent:=False, Value:="(Indiscernible ", _
Type:=msoPropertyTypeString
.add Name:="SufFix", LinkToContent:=False, Value:=")", _
Type:=msoPropertyTypeString
Case 2
.add Name:="PreFix", LinkToContent:=False, Value:="-GOTO-", _
Type:=msoPropertyTypeString
.add Name:="SufFix", LinkToContent:=False, Value:="", _
Type:=msoPropertyTypeString
Case 3
.add Name:="PreFix", LinkToContent:=False, Value:="****", _
Type:=msoPropertyTypeString
.add Name:="SufFix", LinkToContent:=False, Value:="", _
Type:=msoPropertyTypeString
End Select
End If
End With

When I close the active document [Document_Close module], I am deleting these CustomDocumentProperties. Now this works fine with a "DOCX" file. However, it fails when I'm closing a "DOC" file. I sometimes have to use a DOC document.

I'm using this for deleting:


If ActiveDocument.CustomDocumentProperties.Count > 0 Then
For Each cstprop In ActiveDocument.CustomDocumentProperties
cstprop.Delete
Next cstprop
End If


I've even tried individually deleting like this:


ActiveDocument.CustomDocumentProperties.Item("PreFix").Delete
ActiveDocument.CustomDocumentProperties.Item("SufFix").Delete
'I got this bit here http://www.vbaexpress.com/forum/showthread.php?28849-Delete-Custom-Document-Properties


Still it shows that it runs the code, but does not delete the custom property. This is failing only for DOC files. The For...Next loop works perfectly for DOCX files.

I have not set an On Error Resume Next handler in the delete module.

Any help in understanding this would be great.