【发布时间】:2010-12-03 12:02:04
【问题描述】:
我想查找 字符之间的文本,然后将任何找到的文本转换为“正常”大小写,其中单词的第一个字母大写。到目前为止,这是我所拥有的:
Function findTextBetweenCarots() As String
Dim strText As String
With Selection
.Find.Text = "<" ' what about <[^0-9]+> ?
.Find.Forward = True
.Find.Wrap = wdFindContinue
End With
Selection.Find.Execute
' Application.Selection. ' how do I get the text between the other ">"?
findCarotSymb = Application.Selection.Text
End Function
或者,有更好的方法吗?我还使用 VBScript Regex 5.5 库解决了这个问题,该库适用于简单文档,但不适用于具有复杂表格的某些文档。例如,尝试将文本加粗(为简单起见):
Sub BoldUpperCaseWords()
Dim regEx, Match, Matches
Dim rngRange As Range
Set regEx = New RegExp
regEx.Pattern = "<[^0-9]+>"
regEx.IgnoreCase = False
regEx.Global = True
Set Matches = regEx.Execute(ActiveDocument.Range.Text)
For Each Match In Matches
ActiveDocument.Range(Match.FirstIndex, Match.FirstIndex + Len(Match.Value)).Bold = True
Next
End Sub
不适用于包含表格的文档。事实上,它甚至不会加粗正确的文本(<> 之间的文本。这让我相信我在这里缺少一个更广泛的问题。
【问题讨论】: