|
* 楼主,请将要处理的文件放入一个文件夹中,打包(或复制)备份后,应用下面的宏:
- Sub LoopFolder_duquancai_2021_05_16()
- Dim SelectFolder$
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show Then SelectFolder = .SelectedItems(1) & "" Else End
- End With
- If MsgBox("是否处理文件夹 " & """" & SelectFolder & """" & " ?", 4 + 16) = vbNo Then End
- Dim pPath$, f As Object, fd As Object, fso As Object, Stack$(), top&, n&, stxt$, doc As Document, x&
- pPath = SelectFolder
- Set fso = CreateObject("Scripting.FileSystemObject")
- top = 1
- ReDim Stack(0 To top)
- Do While top >= 1
- For Each f In fso.getFolder(pPath).Files
- n = n + 1
- stxt = f.Path
- If stxt Like "*.doc*" Then
- Set doc = Documents.Open(FileName:=stxt)
- ActiveWindow.ActivePane.View.Zoom.PageFit = wdPageFitBestFit
- With doc.Content.Find
- .ClearFormatting
- .Text = "推荐的中标候选人和中标人"
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- With .Parent
- .Select
- With Selection
- With .Font
- .Parent.MoveRight Unit:=wdCell, Count:=8
- .NameFarEast = "华文中宋"
- .NameAscii = "Times New Roman"
- .Size = 20
- .Bold = True
- .ColorIndex = wdRed
- .Kerning = 0
- .DisableCharacterSpaceGrid = True
- End With
- With .ParagraphFormat
- .CharacterUnitFirstLineIndent = 0
- .FirstLineIndent = CentimetersToPoints(0)
- .Alignment = wdAlignParagraphCenter
- .AutoAdjustRightIndent = False
- .DisableLineHeightGrid = True
- End With
- .HomeKey 6
- End With
- End With
- Loop
- End With
- doc.Close SaveChanges:=wdSaveChanges
- x = x + 1
- End If
- Next
- For Each fd In fso.getFolder(pPath).subFolders
- Stack(top) = fd.Path
- top = top + 1
- If top > UBound(Stack) Then ReDim Preserve Stack(0 To top)
- Next
- If top > 0 Then pPath = Stack(top - 1): top = top - 1
- Loop
- Set f = Nothing
- Set fd = Nothing
- Set fso = Nothing
- MsgBox "文件夹包含 " & n & " 个文件!" & vbCr & "共处理 Word 文档(*.docx/*.doc) " & x & " 个!", 0 + 48
- End Sub
复制代码 |
|