Board logo

标题: [其他] 请教一个WORD 2007 VBA批量替换问题。。。 [打印本页]

作者: shixn    时间: 2014-8-21 22:45     标题: 请教一个WORD 2007 VBA批量替换问题。。。

现在有大约40份文档,存在一个文件夹里。文件中可能含有某个人名,比如“张三丰”。现在想将所有文件中的“张三丰”全部替换成“周杰伦”

百度了一段代码,发现使用Application.FileSearch可以批量搜索替换,但是坑爹的是word2007里取消这个功能了。。。。

这下该怎么办。。。

求一个替代解决办法,万分感谢,激骚伺候!

Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim myPas As String, myPath As String, i As Integer, myDoc As Document
Dim fs As New FileSearh

With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "选择目标文件夹"
    If .Show = -1 Then
      myPath = .SelectedItems(1)
    Else
      Exit Sub
    End If
End With
myPas = InputBox("请输入打开密码:")

With Application.FileSearch
    .LookIn = myPath
    .FileType = msoFileTypeWordDocuments
    If .Execute > 0 Then
      For i = 1 To .FoundFiles.Count
        Set myDoc = Documents.Open(fileName:=.FoundFiles(i), Passworddocument:=myPas)
        Selection.Find.ClearFormatting
        Selection.Find.Replacement.ClearFormatting
        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
End Sub
作者: handsomeken    时间: 2014-8-22 09:22

posted by wap, platform: Nokia Lumia 920
发给助理,ctrl f
作者: Benthal    时间: 2014-8-22 09:31

引用:
原帖由 handsomeken 于 2014-8-22 09:22 发表
posted by wap, platform: Nokia Lumia 920
发给助理,ctrl f
:D:D:D
作者: liuxuu    时间: 2014-8-22 09:49

哈,我有办法,楼主百度WORD必备工具箱,装上就有你要的功能了,还有N多实用功能哦,免费的

绝对不是广告

觉得好就加祭扫

[ 本帖最后由 liuxuu 于 2014-8-22 09:50 编辑 ]
作者: waterking    时间: 2014-8-24 00:21

posted by wap, platform: iPhone UC
引用:
原帖由 @liuxuu  于 2014-8-22 09:49 发表
哈,我有办法,楼主百度WORD必备工具箱,装上就有你要的功能了,还有N多实用功能哦,免费的

绝对不是广告

觉得好就加祭扫
这个牛逼!




欢迎光临 TGFC Lifestyle (http://bbs.tgfcer.com/) Powered by Discuz! 6.0.0