利用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
date1 = InputBox("Please input the update date:", "Input Date: ", date1)
If date1 = "" And StrPtr(date1) = 0 Then
Exit Sub
End If
''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
''' Confirm update information  ''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
updateInfo = "Update information:" & vbCrLf & vbCrLf & _
"Document name    " & vbTab & ":  " & docuName & vbCrLf & _
"Issue number     " & vbTab & ":  " & issueNumber & vbCrLf & _
"Prepared/modified" & vbTab & ":  " & author & vbCrLf & _
"Checked/released " & vbTab & ":  " & checker & vbCrLf & _
"Update date      " & vbTab & ":  " & date1 & vbCrLf & vbCrLf & vbCrLf & _
"Please confirm to update the document."
result = MsgBox(updateInfo, vbYesNo, "Confirm to update the document")
If (result = 6) Then
''' Update custom properties
On Error GoTo errHandler01
ActiveDocument.CustomDocumentProperties("_DocuName") = docuName
On Error GoTo errHandler02
ActiveDocument.CustomDocumentProperties("_IssueNumber") = issueNumber
On Error GoTo errHandler03
ActiveDocument.CustomDocumentProperties("_Prepared/Modified") = author
On Error GoTo errHandler04
ActiveDocument.CustomDocumentProperties("_Checked/Released") = checker
On Error GoTo errHandler05
ActiveDocument.CustomDocumentProperties("_UpdateDate") = date1
''' resume error handler
On Error GoTo errHandler00
'''update all fields, for TOC field, this will only update page number.
Dim aField As Field
For Each aStory In ActiveDocument.StoryRanges
For Each aField In aStory.Fields
aField.Update
Next aField
Next aStory
End If
Exit Sub
errHandler00:
MsgBox Err.Description
''''''''''''''''''''''''''''''''''''''''''''
''' Create custom properties '''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
'''if custom properties cannot be updated(do not exist), create relevant properties
errHandler01:
ActiveDocument.CustomDocumentProperties.Add _
Name:="_DocuName", LinkToContent:=False, Value:=docuName, _
Type:=msoPropertyTypeString
Resume Next
errHandler02:
ActiveDocument.CustomDocumentProperties.Add _
Name:="_IssueNumber", LinkToContent:=False, Value:=issueNumber, _
Type:=msoPropertyTypeString
Resume Next
errHandler03:
ActiveDocument.CustomDocumentProperties.Add _
Name:="_Prepared/Modified", LinkToContent:=False, Value:=author, _
Type:=msoPropertyTypeString
Resume Next
errHandler04:
ActiveDocument.CustomDocumentProperties.Add _
Name:="_Checked/Released", LinkToContent:=False, Value:=checker, _
Type:=msoPropertyTypeString
Resume Next
errHandler05:
ActiveDocument.CustomDocumentProperties.Add _
Name:="_UpdateDate", LinkToContent:=False, Value:=date1, _
Type:=msoPropertyTypeString
Resume Next
''''''''''''''''''''''''''''''''''''''''''''
'''variable initializing when custom properties do not exist in current document
errHandler06:
author = "_AUTHOR_"
Resume Next
errHandler07:
checker = "_CHECKER_"
Resume Next
errHandler08:
date1 = Date
Resume Next
End Sub
Sub NS_Cope()
'
' NS_Cope 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 COPE
'''for numbering system NEW and OLD, you should change 13 and 15 to correct number
docuName = Left(ActiveDocument.Name, 13)
issueNumber = Mid(ActiveDocument.Name, 15, 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
date1 = InputBox("Please input the update date:", "Input Date: ", date1)
If date1 = "" And StrPtr(date1) = 0 Then
Exit Sub
End If
''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
''' Confirm update information  ''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
updateInfo = "Update information:" & vbCrLf & vbCrLf & _
"Document name    " & vbTab & ":  " & docuName & vbCrLf & _
"Issue number     " & vbTab & ":  " & issueNumber & vbCrLf & _
"Prepared/modified" & vbTab & ":  " & author & vbCrLf & _
"Checked/released " & vbTab & ":  " & checker & vbCrLf & _
"Update date      " & vbTab & ":  " & date1 & vbCrLf & vbCrLf & vbCrLf & _
"Please confirm to update the document."
result = MsgBox(updateInfo, vbYesNo, "Confirm to update the document")
If (result = 6) Then
''' Update custom properties
On Error GoTo errHandler01
ActiveDocument.CustomDocumentProperties("_DocuName") = docuName
On Error GoTo errHandler02
ActiveDocument.CustomDocumentProperties("_IssueNumber") = issueNumber
On Error GoTo errHandler03
ActiveDocument.CustomDocumentProperties("_Prepared/Modified") = author
On Error GoTo errHandler04
ActiveDocument.CustomDocumentProperties("_Checked/Released") = checker
On Error GoTo errHandler05
ActiveDocument.CustomDocumentProperties("_UpdateDate") = date1
''' resume error handler
On Error GoTo errHandler00
'''update all fields, for TOC field, only update page number.
Dim aField As Field
For Each aStory In ActiveDocument.StoryRanges
For Each aField In aStory.Fields
aField.Update
Next aField
Next aStory
End If
Exit Sub
errHandler00:
MsgBox Err.Description
''''''''''''''''''''''''''''''''''''''''''''
''' Create custom properties '''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''
'''if custom properties cannot be updated(do not exist), create relevant properties
errHandler01:
ActiveDocument.CustomDocumentProperties.Add _
Name:="_DocuName", LinkToContent:=False, Value:=docuName, _
Type:=msoPropertyTypeString
Resume Next
errHandler02:
ActiveDocument.CustomDocumentProperties.Add _
Name:="_IssueNumber", LinkToContent:=False, Value:=issueNumber, _
Type:=msoPropertyTypeString
Resume Next
errHandler03:
ActiveDocument.CustomDocumentProperties.Add _
Name:="_Prepared/Modified", LinkToContent:=False, Value:=author, _
Type:=msoPropertyTypeString
Resume Next
errHandler04:
ActiveDocument.CustomDocumentProperties.Add _
Name:="_Checked/Released", LinkToContent:=False, Value:=checker, _
Type:=msoPropertyTypeString
Resume Next
errHandler05:
ActiveDocument.CustomDocumentProperties.Add _
Name:="_UpdateDate", LinkToContent:=False, Value:=date1, _
Type:=msoPropertyTypeString
Resume Next
''''''''''''''''''''''''''''''''''''''''''''
'''variable initializing when custom properties do not exist in current document
errHandler06:
author = "_AUTHOR_"
Resume Next
errHandler07:
checker = "_CHECKER_"
Resume Next
errHandler08:
date1 = Date
Resume Next
End Sub
Sub IssueNo()
'
' InsertIssueNo Macro
' Macro recorded 02/22/2012 by songv
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DOCPROPERTY  _IssueNumber ", PreserveFormatting:=True
End Sub
Sub UpdateDate()
'
' InsertUpdateDate Macro
' Macro recorded 02/22/2012 by songv
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DOCPROPERTY  _UpdateDate ", PreserveFormatting:=True
End Sub
Sub author()
'
' InsertAuthor Macro
' Macro recorded 02/22/2012 by songv
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DOCPROPERTY  _Prepared/Modified ", PreserveFormatting:=True
End Sub
Sub checker()
'
' InsertChecker Macro
' Macro recorded 02/22/2012 by songv
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DOCPROPERTY  _Checked/Released ", PreserveFormatting:=True
End Sub
Sub docuName()
'
' InsertDocuName Macro
' Macro recorded 02/22/2012 by songv
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DOCPROPERTY  _DocuName ", PreserveFormatting:=True
End Sub
Sub ShowAll()
'
' ShowAll Macro
' Macro created 02/29/2012 by songv
'
ActiveWindow.View.ShowAll = True
End Sub
Sub HideAll()
'
' ShowAll Macro
' Macro created 02/29/2012 by songv
'
ActiveWindow.View.ShowAll = False
End Sub

Word 使用宏根据文件名实现文件版本号自动更新_rev00相关推荐

  1. 利用gulp,当引入文件改动时,版本号自动更新~

    gulp自动更新版本号 安装依赖 yarn add gulp-rev yarn add gulp-rev-collector 本次依赖的版本号为: "gulp": "^3 ...

  2. Word中插入参考文献及其引用并能够自动更新的方法

    1.将鼠标光标移到文本中需要第一次引用参考文献的位置,点击"插入"菜单,选择"引用",接着选择"脚注和尾注",弹出"脚注和尾注&q ...

  3. Vim winmanager文件浏览自动更新

    使用winmanger插件中发现其中引用的fileexplorer不能自动更新到当前文件夹. 将vim/plugin/winfileexplorer.vim 中的函数FileExplorer_Star ...

  4. linux svn提交的时候同时更新web目录文件,linux下svn提交文件后自动更新到web目录中...

    SVN上传时同步到服务器其它目录 svn/examPro/hooks/目录下: 能看到一堆模版钩子文件,我们需要的是post-commit.tmpl, copy一份,命名为post-commit.然后 ...

  5. [JetBrains Rider] 在保存文件时自动更新文件头的方法

    首先要创建一个文件头模板,保存 然后需要新建一个 Code CleanUp 行为,只有这样才能点开 Update file header 行为 新建完成,保存 在 保存时行为 中选择刚刚新建的行为,保 ...

  6. 代码操作Word时,目录自动更新的两种方法

    最近的项目中有一个功能点为:根据分析数据库并生成报告.不过不是大数据.数据挖掘之类,报告的内容.组织方式都是事先固定下来的.实现的方式为,在普通word文档中插入书签制成模板,然后程序使用OpenXM ...

  7. linux 提取ko文件,Linux获取so/ko文件版本号教程

    一.需要获取版本号的原因 从使用角度而言,有时只有特定版本的库才支持某些功能,所以我们需要确定库文件版本号. 从安全加固角度而言,有些版本存在漏洞有些版本不存在漏洞,所以我们需要获取版本号以确定当前使 ...

  8. word、excel、ppt 办公文件 在线预览

    如果想要免费的,可以用 openoffice,实现原理就是: 通过第三方工具openoffice,将word.excel.ppt.txt等文件转换为pdf文件流:当然如果装了Adobe Reader ...

  9. C++获取exe文件版本号

    #pragma comment(lib, "version.lib")//返回文件版本号 //@params:filename:文件名 string GetFileVersion( ...

最新文章

  1. Qt使用教程:使用Qt Quick UI表单(五)
  2. POI异步导入Excel兼容xsl和xlsx
  3. 实验11.1 指针数组、指针与函数 6-5 查找子串
  4. Linux Shell常用技巧(三)
  5. SIP协议(基础技术知识)
  6. 红橙Darren视频笔记 筛选View 属性动画 Adapter模式 组合动画AnimatorSet 观察者模式(对比Android ListView) 练习
  7. 360站长工具-免费360链接提交主动推送收录工具自带收录排名蜘蛛查询
  8. 硬盘的那些事(主分区、扩展分区、逻辑分区、活动分区、系统分区、启动分区、引导扇区、MBR等)
  9. MT【337】糖水不等式
  10. 网络安全守护神(SOC)
  11. JetBrains提示“No suitable licenses associated with account ”
  12. 揭开特斯拉的地图“疑云”
  13. 机器学习笔记2:建立模型一般所需步骤
  14. 《雍正皇帝》文化专有词泰译研究(选题缘由)
  15. java pdf添加文字水印(非常专业)
  16. java 数据库工资管理系统设计_数据库课程设计—企业工资管理系统(java版完整代码)...
  17. 剑魂之刃登录显示服务器异常,《剑魂之刃》更新后链接服务器失败的原因及解决办法...
  18. 【HTML 教程系列第 11 篇】HTML 中常用的文本格式化标签
  19. Jest测试框架入门之匹配器与测试异步代码
  20. 检测下你的显示器是否有问题

热门文章

  1. NPDP知识推送-第六章市场研究(4)
  2. 还我一个干净的Mac OS(如何彻底删除不需要的App)
  3. 卷积神经网络(CNN)经典模型分析(一)
  4. python二级证书含金量排名_计算机二级证书含金量有多高?你真的知道吗???...
  5. Ubuntu下安装PCL1.12.1点云库经验分享
  6. Markdown插入url图片
  7. 持续性混吃等死,间歇性踌躇满志 --转自头条
  8. 金融核心业务流程整理
  9. ElasticSearch 数据迁移
  10. Android中处理大图片时图片压缩