View Single Post
 
Old 03-09-2021, 11:46 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
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 ofgmayor has much to be proud of
Default

The DIM statements are not required for the macro. As for the rest,you can't put a date in a date field that is not a date, nor a number in a number field that is not a number.
I would suggest using error trapping to avoid crashes while testing the code.

Code:
Option Explicit

Private Sub Document_New()
    AddProp "APS_ContractNumber", False, 4, "[Contract Number]"
    AddProp "APS_DocumentCode", False, 4, "[Document Code]"
    AddProp "APS_DocumentNumber", False, 4, "[Document Number]"
    AddProp "APS_DocumentTitle", False, 4, "[Document Title]"
    AddProp "APS_DocumentType", False, 4, "[Document Type]"
    AddProp "APS_Revision", False, 4, "[RR]"
    AddProp "APS_RevisionDate", False, 3, "01/01/2000"
    AddProp "APS_SubjectCode", False, 4, "[Subject Code]"
    AddProp "APS_UniqueIdentifier", False, 4, "[XXX]"
End Sub

Private Sub AddProp(sName As String, bLink As Boolean, lType As Long, sValue As String)
Dim oProp As DocumentProperty
    With ActiveDocument
        For Each oProp In .CustomDocumentProperties
            If oProp.Name = sName Then
                oProp.Value = sValue
                GoTo lbl_Exit
            End If
        Next oProp
        .CustomDocumentProperties.Add _
                Name:=sName, _
                LinkToContent:=bLink, _
                Type:=lType, _
                Value:=sValue
    End With
lbl_Exit:
    Set oProp = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote