【问题标题】:Performing an action using VBA使用 VBA 执行操作
【发布时间】:2013-02-01 20:59:21
【问题描述】:

我在 MS Word 文件中有一段文本,如下所示:

[[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>

我该怎么办?

【问题讨论】:

  • 搜索和替换?您可以将搜索和替换操作记录为 VBA 宏并对其进行修改,以便再次使用它。
  • 不是通过搜索和替换。它不是这样发生的。
  • 你说的没有发生是什么意思?搜索[[ul]] 并用&lt;list identifier="" list-style="Unordered"&gt; 替换它不起作用,还是您不想那样做?
  • 尊敬的先生,我想明智地执行动作块而不是单独执行。由于文档有更多这样的列表。

标签: vba ms-word


【解决方案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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2014-04-16
  • 1970-01-01
  • 1970-01-01
  • 2021-02-03
  • 2014-11-12
  • 1970-01-01
  • 1970-01-01
  • 2018-08-04
相关资源
最近更新 更多