我有一个 Word 文档,其中的文本块标有名为“Princple”和“BusinessRule”的样式。这些文本块分散在整个文档中。我想按照它们出现的顺序查找这些块并将其复制到单独的文档中。我正在使用的代码是:
Dim SelStyle As String
'SelStyle = "Principle"
SelStyle = "BusinessRule"
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Style = SelStyle
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Copy
Windows("Document1").Activate
Selection.TypeParagraph
Selection.PasteAndFormat (wdFormatPlainText)
Selection.TypeParagraph
Windows("mainDoc.docx").Activate
Selection.MoveRight Unit:=wdCharacter, Count:=1
如您所见,这是一个手动过程:首先取消注释 Principle,提取所有这些,然后注释 Princple 并取消注释 BusinessRule。不是很好。有什么方法可以搜索 .Style="Principle" 或 .Style="BusinessRule" 以便我按顺序获取它们?(其次,如果您有建议循环浏览整个文档来执行此操作,我将不胜感激。:-))
谢谢 - 比尔