|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
* 楼主,请备份后应用下面的宏:(借用 相见是缘 的代码一下,谢谢!)
- Sub aaab_FSO_循环遍历文件夹_删除红色字符()
- On Error Resume Next
- Dim objShell As Object, objFolder As Object, pPath$, f As Object, fd As Object, fso As Object, Stack$(), top&, n&, stxt$, doc As Document, x&
- Set objShell = CreateObject("Shell.Application")
- Set objFolder = objShell.BrowseForFolder(0, "请选择文件夹!", 0, 0)
- pPath = objFolder.self.Path & ""
- Set objShell = Nothing
- Set objFolder = Nothing
- If MsgBox("请确认!是否处理文件夹 " & pPath & " ?", 4 + 16) = vbNo Then Exit Sub
- 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, Visible:=False)
- '''
- '删除所有域/删除红色字符
- With doc
- .Fields.Unlink
- With .Content.Find
- .Font.Color = wdColorRed
- .Execute FindText:="", replacewith:="", Format:=True, Replace:=wdReplaceAll
- End With
- ActiveWindow.ActivePane.View.Zoom.Percentage = 89
- .Close SaveChanges:=wdSaveChanges
- End With
- '''
- 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
复制代码 |
评分
-
1
查看全部评分
-
|