本帖最后由 13907933959 于 2017-9-27 10:56 编辑
网友好!
Sub 循环遍历文件夹() On Error Resume Next Dim fd As FileDialog, i As Long,doc As Document, p As String, t As Long, s As Long, j As Paragraph Set fd =Application.FileDialog(msoFileDialogFolderPicker) If fd.Show = -1 Then p =fd.SelectedItems(1) Else Exit Sub Set fd = Nothing If MsgBox("是否处理文件夹 " & p & "?", vbYesNo + vbExclamation, "循环遍历文件夹")= vbNo Then Exit Sub With Application.FileSearch .NewSearch .LookIn = p .SearchSubFolders = True .FileName = "*.doc" If .Execute > 0 Then For i = 1 To.FoundFiles.Count Set doc =Documents.Open(FileName:=.FoundFiles(i)) '此处加入你要处理的……………………………………… '……………………………………………………………… '………… doc.Close savechanges:=wdSaveChanges Next i MsgBox "总共处理了" & .FoundFiles.Count& " 个文件!", vbOKOnly + vbExclamation,"doc_process" Else MsgBox "未找到要处理的文件!", vbOKOnly +vbCritical, "doc_process" End If End With End Sub
|