操纵Word文档

时间:2012-02-14 14:55:24

标签: .net vba ms-word

我们有一堆Microsoft Word文档,其中某些区域有“标题2”。有没有办法通过VBA或.NET代码我们可以打开这个文件,找出“标题2”区域在哪里并自动将它们改为“标题3”?手动执行此操作非常耗时且编程解决方案很不错。

1 个答案:

答案 0 :(得分:0)

Selection.Find.ClearFormatting

    Selection.Find.Style = ActiveDocument.Styles("YourOldStyle")
    Selection.Find.Replacement.ClearFormatting
    Selection.Find.Replacement.Style = ActiveDocument.Styles("YourNewStyle")

    With Selection.Find

        .Text = ""
        .Replacement.Text = ""
        .Forward = True

        .Wrap = wdFindContinue
        .Format = True
        .MatchCase = False

        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False

    End With

    Selection.Find.Execute Replace:=wdReplaceAll