利用Word宏功能实现文件版本号及相关内容自动更新,最初版。
实现功能:通过Word文件自定义属性结合域和宏实现自动更新文件相关信息,包括:
通过InputBox输入作者/核查/更新日期;
通过文件名获取文档编码和文件版本号。
另外通过几个自定义宏可以实现快速域插入以及文档特殊标记符号的显示和隐藏。
Attribute VB_Name = "Docu"
Sub NS_New()
'
' NS_New Macro
' Macro created 02/22/2012 by songv
'
''''''''''''''''''''''''''''''''''''''''''''
''' Define variables ''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
Dim docuName, author, checker, issueNumber, updateInfo, date1 As String
Dim result As Integer
''''''''''''''''''''''''''''''''''''''''''''
''' Initial variables '''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
docuName = "DDXXXXxxxxExx"
issueNumber = "00"
On Error GoTo errHandler06
author = ActiveDocument.CustomDocumentProperties("_Prepared/Modified")
On Error GoTo errHandler07
checker = ActiveDocument.CustomDocumentProperties("_Checked/Released")
On Error GoTo errHandler08
date1 = ActiveDocument.CustomDocumentProperties("_UpdateDate")
result = 0
''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
''' Get update information ''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
On Error GoTo errHandler00
'''get document name and issue number from file name, only valid for numbering system NEW
'''for numbering system COPE and OLD, you should change 11 and 13 to correct number
docuName = Left(ActiveDocument.Name, 11)
issueNumber = Mid(ActiveDocument.Name, 13, 2)
author = InputBox("Please input the author (prepared / modified)", "Input Author: ", author)
'''StrPtr will check the variable address in memory,
'''StrPtr(author) = 0 means it does not exist in memory, it is NULL.
'''This confirms user pressed Cancel button.
If author = "" And StrPtr(author) = 0 Then
Exit Sub
End If
checker = InputBox("Please input the checker (checked / released)", "Input Checker: ", checker)
If checker = "" And StrPtr(checker) = 0 Then
Exit Sub
End If