|
* 请 楼主 重新测试一下(备份原文件后再应用):
- Sub LoopFolder_gbgbxgb()
- Dim d As Object, thePath$, theStr$, i&, j&, k&, doc As Document
- thePath = SelectFolder
- Set d = CreateObject("Scripting.Dictionary")
- d(thePath) = ""
- Do While i < d.Count
- thePath = d.keys()(i)
- theStr = Dir(thePath, vbDirectory)
- Do While theStr <> ""
- If theStr <> "." And theStr <> ".." Then
- If (GetAttr(thePath & theStr) And vbDirectory) = vbDirectory Then
- d(thePath & theStr & "") = ""
- Else
- j = j + 1
- If thePath & theStr Like "*.doc*" Then
- Set doc = Documents.Open(FileName:=thePath & theStr)
- doc.Fields.Unlink
- doc.Close SaveChanges:=wdSaveChanges
- k = k + 1
- End If
- End If
- End If
- theStr = Dir
- Loop
- i = i + 1
- Loop
- Set d = Nothing
- MsgBox "文件夹包含 " & j & " 个文件!" & i - 1 & " 个子文件夹!" & vbCr & "共处理 Word 文档(*.docx/*.doc) " & k & " 个!", 0 + 48
- End Sub
- Function SelectFolder() As String
- With Application.FileDialog(msoFileDialogFolderPicker)
- If .Show Then SelectFolder = .SelectedItems(1) & "" Else End
- End With
- If MsgBox("是否处理文件夹 " & """" & SelectFolder & """" & " ?", 4 + 16) = vbNo Then End
- End Function
复制代码 |
|