使用带通配符的 FIND 在小括号之间查找特定文本
Find specific TEXT between Small brackets using FIND with wildcard
我需要在小括号 ()
之间找到特定的文本 " PL"
即
文本标准:
- text " PL" - 两个字母都是大写并且在 "PL" 之前有一个 space
- 文本应为粗体
- 文本应位于小括号之间,即。 ()
示例文本:
- Portugues SA(BCP PL,买入):(目标价:0.22 欧元)银行
- Jeronimo Martins SGPS SA(JMT PL,买入):(目标价:19.60 欧元)2Q21 回顾
- Ibersol SGPS SA(IBS PL,中性):(目标价:6.50 欧元)Cinven 获得控制权
VBA代码:
With Selection.Find
.Text = "\((.*?)\)" ' WhildCard
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With
If Selection.Find.Found Then
'if found then need to select the paragraph and do something with it.
End If
如果可以使用Wildcard
,请帮忙
试试这个代码:
Sub test1()
With ActiveDocument.Range.Find 'or Selection.Range.Find
.Text = "\(?*\)"
.MatchWildcards = True
Do While .Execute
If InStr(.Parent.Text, " PL") And .Parent.Font.Bold Then
'do something with it
.Parent.Paragraphs(1).Range.Delete
End If
Loop
End With
End Sub
不带括号的 Edit2 模式
Sub test2()
Dim rng As Range
With ActiveDocument.Range.Find
.Text = " PL"
.MatchWildcards = True
Do While .Execute
If .Parent.Font.Bold Then
.Parent.Paragraphs(1).Range.Delete
End If
Loop
End With
End Sub
我需要在小括号 ()
之间找到特定的文本 " PL"
即
文本标准:
- text " PL" - 两个字母都是大写并且在 "PL" 之前有一个 space
- 文本应为粗体
- 文本应位于小括号之间,即。 ()
示例文本:
- Portugues SA(BCP PL,买入):(目标价:0.22 欧元)银行
- Jeronimo Martins SGPS SA(JMT PL,买入):(目标价:19.60 欧元)2Q21 回顾
- Ibersol SGPS SA(IBS PL,中性):(目标价:6.50 欧元)Cinven 获得控制权
VBA代码:
With Selection.Find
.Text = "\((.*?)\)" ' WhildCard
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
.Execute
End With
If Selection.Find.Found Then
'if found then need to select the paragraph and do something with it.
End If
如果可以使用Wildcard
,请帮忙
试试这个代码:
Sub test1()
With ActiveDocument.Range.Find 'or Selection.Range.Find
.Text = "\(?*\)"
.MatchWildcards = True
Do While .Execute
If InStr(.Parent.Text, " PL") And .Parent.Font.Bold Then
'do something with it
.Parent.Paragraphs(1).Range.Delete
End If
Loop
End With
End Sub
不带括号的 Edit2 模式
Sub test2()
Dim rng As Range
With ActiveDocument.Range.Find
.Text = " PL"
.MatchWildcards = True
Do While .Execute
If .Parent.Font.Bold Then
.Parent.Paragraphs(1).Range.Delete
End If
Loop
End With
End Sub