|
- Sub 批处理_查找替换页眉内容()
- Application.ScreenUpdating = 0
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Title = "请选择需要批量打印的文件夹"
- If .Show = -1 Then
- 路径 = .SelectedItems(1)
- Else
- MsgBox "没有选择文件夹,程序退出...", , "操作取消"
- Exit Sub
- End If
- End With
-
- Set FSO对象 = CreateObject("Scripting.FileSystemObject")
- Set 文件夹 = FSO对象.GetFolder(路径)
- For Each 文件 In 文件夹.files
- Call test1(CStr(文件))
- Next
- Application.ScreenUpdating = 1
- End Sub
- Sub test1(文件路径)
- Dim 文档 As Document
- Set 文档 = Documents.Open(文件路径)
- '把代码放到这里,注意如果会用到activedocument,那么改成文档.
- Dim 页眉 As HeaderFooter, 节 As Section
- For Each 节 In 文档.Sections
- For Each 页眉 In 节.Headers
- With 页眉.Range.Find
- .ClearFormatting
- .MatchWildcards = 1
- .text = "最近修订日期:2023/[0-9]{2}/[0-9]{2}"
- .Replacement.ClearFormatting
- .Replacement.text = "最近修订日期:2025/02/15"
- .Execute Replace:=wdReplaceAll
- End With
- Next
- Next
- 文档.Save
- 文档.Close
- End Sub
复制代码 |
|