使用VBA执行操作

时间:2013-01-29 09:26:40

标签: vba ms-word word-vba

我在MS文件文件中有一个文本块,如下所示:

[[ul]]
•   For the near term, all Cendoc content will be ingested into the NextBook_Cendoc_June2011 database. 
•   You must navigate to and open this database before you can ingest Cendoc XML. 
•   You can locate this database for the first time by selecting the DATABASE option from the blue navigation bar at the top of the screen. Select the “Browse all database/choose a database” option. Select the “NextBook_Cendoc_June2011” link from the menu. 
[[/ul]]

我需要使用VBA

输出如下
<list identifier="" list-style="Unordered">
<item identifier=""""><para identifier="">For the near term, all Cendoc content will be ingested into the NextBook_Cendoc_June2011 database.</para></item>
<item identifier=""""><para identifier="">You must navigate to and open this database before you can ingest Cendoc XML.</para></item>
<item identifier=""""><para identifier="">You can locate this database for the first time by selecting the DATABASE option from the blue navigation bar at the top of the screen. Select the “Browse all database/choose a database” option. Select the “NextBook_Cendoc_June2011” link from the menu.</para></item>
</list>

我该怎么办?

1 个答案:

答案 0 :(得分:1)

好吧,我做了我的建议,并为你录制了一个搜索和替换宏,这就是我想出来的。

Option Explicit

Sub SearchAndReplace()

    Selection.HomeKey Unit:=wdStory

    With Selection.Find
        .Text = "[[ul]]"
        .Replacement.Text = "<list identifier="""" list-style=""Unordered"">"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll


    With Selection.Find
        .Text = "•   "
        .Replacement.Text = _
            "<item identifier=""""""""><para identifier="""">"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll


    With Selection.Find
        .Text = "[[/ul]]"
        .Replacement.Text = "</list>"
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

End Sub