将所有大写文本替换为小写字母和 wdTitleSentence

Replace all uppercase text to smallcaps AND wdTitleSentence

这两天我一直被这个问题困扰,找不到解决的方法。 我有一份文件(400 页),我想在其中将所有大写单词替换为 SmallCaps,并将文本设置为“标题句”。 当我注册一个宏时,我找到了我需要的命令:

Selection.Range.Case = wdTitleSentence
Selection.Font.SmallCaps = wdToggle

问题是我找不到将这些命令仅应用于大写单词而不应用于所选文本的方法。

您可以尝试使用通配符搜索,但您需要注意如何指定它,否则您可以将文档中的每个大写字母更改为小型大写字母。

Sub ConvertUpperCase()
   Dim findRange As Range
   Set findRange = ActiveDocument.Content
   
   With findRange.Find
      .ClearFormatting
      'find at least two consecutive capital letters
      .Text = "[A-Z]{2,}"
      .MatchWildcards = True
      Do While .Execute = True
         With findRange
            .Case = wdTitleSentence
            .Font.SmallCaps = True
            .Collapse wdCollapseEnd
         End With
      Loop
   End With
End Sub