【发布时间】:2019-12-28 04:22:26
【问题描述】:
我正在格式化大型文档中的特定类型名称。正确的格式是“术语名称 (REC) [日期]”,其中除日期外,整个短语都是斜体。我目前正在使用以下代码:
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(REC)"
.Replacement.Text = "*"
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Do While Selection.Find.Execute = True
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine, Extend:=wdExtend
Selection.Font.Italic = wdToggle
Selection.EndKey Unit:=wdLine, Extend:=wdMove
Loop
除非斜体短语超过两行,否则这很好用。我得到如下内容:
"期限名称 期限 期限 期限 期限
期限 期限 期限 (REC) [日期]"
第一行没有斜体的地方。 VBA 是否有办法只在光标位置选择当前段落的开头?
请随时提出更好的方法。
【问题讨论】:
标签: vba ms-word textselection