VBA批量修改WORD文档

Dim fs, i, arr(1 To 10000)
Set fs = Application.FileSearch
With fs
    .LookIn = "d:\aa\anquan"
    .FileName = "*.doc"
    .SearchSubFolders = True
    MsgBox "There were " & .FoundFiles.Count & _
     " file(s) found."
    If .Execute > 0 Then
      For i = 1 To .FoundFiles.Count
        'Set myDoc = Documents.Open(FileName:=.FoundFiles(i), Passworddocument:=myPas)
        
        
        Set myDoc = Documents.Open(FileName:=.FoundFiles(i))
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        'MsgBox .FoundFiles(i)
        
    With Selection.Find
        .Text = "文国章"
        .Replacement.Text = "李乐群"
        .Forward = True
        '.Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchByte = True
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
        myDoc.Save
        myDoc.Close
       
        Set myDoc = Nothing
      Next
    End If
End With
   Application.ScreenUpdating = True










MsgBox "ok"

 

转载于:https://my.oschina.net/u/3522527/blog/919454

你可能感兴趣的:(VBA批量修改WORD文档)