查找和替换时将字符串中的第二个字符大写?

时间:2018-08-03 02:51:28

标签: vba ms-word word-vba

极端VBA菜鸟在这里。我正在尝试编写一个宏,该宏搜索每个选项卡及其后的字母,并用选项卡和大写字母替换它。

我已经在附近的互联网文章中找到了以下内容,但是我不确定如何正确编写Replacement.Text行。预先感谢。

Sub Capitaliser()
    With Selection.Find
        Text = "^t?"
        Replacement.Text = UCase(Text)
        Forward = True
        Wrap = wdFindContinue
        Format = False
        MatchCase = False
        MatchWholeWord = False
        MatchWildcards = True
        MatchSoundsLike = False
        MatchAllWordForms = False
        Execute Replace:=wdReplaceAll
    End With
End Sub

1 个答案:

答案 0 :(得分:0)

尝试:

Sub Demo()
Application.ScreenUpdating = False
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "^t[a-z]"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    .Text = UCase(.Text)
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub