View Single Post
 
Old 06-22-2020, 08:53 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

This is an old thread, but a user has reported that the macro I posted doesn't actually work, at least not with the latest versions of my (or Greg's) add-ins. The reason appears to be that simply changing the document property with the posted code is not seen by the document as something that needs to be saved, and so it isn't. So to use it you need to change the code to flag it as unsaved as shown below.


Code:
Option Explicit

Function DocProp(oDoc As Document) As Boolean
Dim oProp As DocumentProperty
Dim bProp As Boolean

Const strName As String = "Department"
Const strValue As String = "Money"
Const lngType As Long = 4        'Text

    On Error GoTo err_Handler

    bProp = False
    For Each oProp In oDoc.CustomDocumentProperties
        If oProp.Name = strName Then
            oProp.value = strValue
            bProp = True
            Exit For
        End If
    Next oProp
    If Not bProp Then
        oDoc.CustomDocumentProperties.Add _
                Name:=strName, _
                LinkToContent:=False, _
                value:=strValue, _
                Type:=lngType
    End If
    For Each oProp In oDoc.CustomDocumentProperties
        If oProp.Name = strName Then
            oProp.value = strValue
            Exit For
        End If
    Next oProp
    oDoc.Saved = False
    DocProp = True
lbl_Exit:
    Exit Function
err_Handler:
    DocProp = False
    Resume lbl_Exit
 End Function
P.S. As this issue may arise again, I have now updated the add-in to version 4.3 to force the save in the Custom Process code so that any process which does not allow Word to see a change, will actually force the document to be saved regardless.
https://www.gmayor.com/document_batch_processes.htm
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com

Last edited by gmayor; 06-23-2020 at 12:21 AM.
Reply With Quote