1. 按住 ALT + F11 键,即可打开 Microsoft Visual Basic for Applications 窗口。
2. 然后,点击插入 > 模块,将以下代码复制并粘贴到新建的空白模块中:
VBA 代码:将当前日期添加到文件名并保存 Word 文档
Public Sub FileSave1()
Dim xDlg As Dialog
Dim xTitle As String
On Error Resume Next
xTitle = ActiveDocument.BuiltInDocumentProperties("Title").Value
xTitle = xTitle & " " & Format((Year(Now() + 1) Mod 100), "20##") & "-" & _
Format((Month(Now() + 1) Mod 100), "0#") & "-" & _
Format((Day(Now()) Mod 100), "0#")
Set xDlg = Dialogs(wdDialogFileSaveAs)
xDlg.Name = xTitle
xDlg.Show
End Sub