|
楼主,请先备份你要处理的文件夹(打包压缩/测试,或复制一份到另一盘),最好是先把两三个文件,放到一个试验文件夹中,来测试下面的宏:(循环遍历文件夹及子文件夹,清除所有域)
- Sub LoopFolder_duquancai()
- 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)
- doc.Fields.Unlink
- 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
复制代码 |
|