通过vba实现替换word里面指定的字符的方法

今天想要实现自动的替换掉word里面的指定的字符,于是想通过vb实现字符的相关替换。具体的代码如下:

vb 代码:



Function ReplaceText(Optional value As String)
   Dim replaceValue As String
   replaceValue = value
   Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "将要替换的内容"
        .Replacement.Text = replaceValue '替换的内容
.Forward
= True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Replace:=wdReplaceAll End Function

至此word里面的相关的文字被全部的替换掉了。

posted on 2018-06-28 18:57  gxg123  阅读(1849)  评论(0编辑  收藏  举报

导航