Select 范围内的特定句子使用 find 方法并将其设为粗体
Select a particular sentence in range using find method and making it bold
首先使用以下代码,我将 selected 段落作为范围,然后我想 bold 从段落开头到第一句结尾的文本,在我的如果是“。”
怎么可能 select 给定范围内的第一个句子?
Dim CON As Range
selection.MoveDown Unit:=wdParagraph, COUNT:=1, Extend:=wdExtend
If selection.Range.ComputeStatistics(wdStatisticLines) < 3 Then
selection.Font.Bold = True
selection.MoveRight Unit:=wdCharacter, COUNT:=1
Else
selection.MoveLeft Unit:=wdCharacter, COUNT:=1
selection.ExtendMode = True
selection.EndKey Unit:=wdLine
selection.MoveDown Unit:=wdLine, COUNT:=2
Set CON = selection.Range
selection.ExtendMode = False
With CON.Find
.Text = ". "
.Forward = False
.Wrap = wdFindStop
.Execute
End With
If CON.Find.Found Then
'' Now here I want to bold the sentence
else
end if
更新
我设置了代码,现在它可以评估找到的内容。
Set CON = selection.Range
selection.ExtendMode = False
Set conFind = CON.Duplicate
'''''''''''''>>''''''''''''
With conFind.Find
.Text = ">>"
.Forward = False
.Wrap = wdFindStop
.Execute
End With
If conFind.Find.Found Then
CON.End = conFind.End
CON.Font.Bold = True
Else
'''''''''''''. ''''''''''''
With conFind.Find
.Text = "^?. "
.Forward = False
.Wrap = wdFindStop
.Execute
End With
If conFind.Find.Found Then
If confind = "S. " Then
conFind.Find.Execute
If conFind.Find.found Then
CON.End = conFind.End
CON.Font.Bold = True
Else
End If
Else
CON.End = conFind.End
CON.Font.Bold = True
End If
Else
''''''''''''', ''''''''''''
With conFind.Find
.Text = ", "
.Forward = False
.Wrap = wdFindStop
.Execute
End With
If conFind.Find.Found Then
CON.End = conFind.End
CON.Font.Bold = True
Else
End If
End If
End If
声明一个额外的Range变量,例如
Dim conFind as Word.Range
然后将其设置为原始范围的副本。将其用于查找 - 如果查找成功,conFind
将是找到的范围。然后将原始Range的终点设置为找到的Range的终点并应用粗体格式。
注意:我更愿意同时创建一个布尔变量来保存 Find.Found 的成功,而不是测试 Range.Find.Found,因为根据我的经验,它更可靠。我保留了您所拥有的代码,但是...
Set CON = selection.Range
selection.ExtendMode = False
Set conFIND = CON.Duplicate
With conFind.Find
.Text = ". "
.Forward = False
.Wrap = wdFindStop
.Execute
End With
If conFind.Find.Found Then
CON.End = conFind.End
CON.Font.Bold = True
else
end if
首先使用以下代码,我将 selected 段落作为范围,然后我想 bold 从段落开头到第一句结尾的文本,在我的如果是“。”
怎么可能 select 给定范围内的第一个句子?
Dim CON As Range
selection.MoveDown Unit:=wdParagraph, COUNT:=1, Extend:=wdExtend
If selection.Range.ComputeStatistics(wdStatisticLines) < 3 Then
selection.Font.Bold = True
selection.MoveRight Unit:=wdCharacter, COUNT:=1
Else
selection.MoveLeft Unit:=wdCharacter, COUNT:=1
selection.ExtendMode = True
selection.EndKey Unit:=wdLine
selection.MoveDown Unit:=wdLine, COUNT:=2
Set CON = selection.Range
selection.ExtendMode = False
With CON.Find
.Text = ". "
.Forward = False
.Wrap = wdFindStop
.Execute
End With
If CON.Find.Found Then
'' Now here I want to bold the sentence
else
end if
更新
我设置了代码,现在它可以评估找到的内容。
Set CON = selection.Range
selection.ExtendMode = False
Set conFind = CON.Duplicate
'''''''''''''>>''''''''''''
With conFind.Find
.Text = ">>"
.Forward = False
.Wrap = wdFindStop
.Execute
End With
If conFind.Find.Found Then
CON.End = conFind.End
CON.Font.Bold = True
Else
'''''''''''''. ''''''''''''
With conFind.Find
.Text = "^?. "
.Forward = False
.Wrap = wdFindStop
.Execute
End With
If conFind.Find.Found Then
If confind = "S. " Then
conFind.Find.Execute
If conFind.Find.found Then
CON.End = conFind.End
CON.Font.Bold = True
Else
End If
Else
CON.End = conFind.End
CON.Font.Bold = True
End If
Else
''''''''''''', ''''''''''''
With conFind.Find
.Text = ", "
.Forward = False
.Wrap = wdFindStop
.Execute
End With
If conFind.Find.Found Then
CON.End = conFind.End
CON.Font.Bold = True
Else
End If
End If
End If
声明一个额外的Range变量,例如
Dim conFind as Word.Range
然后将其设置为原始范围的副本。将其用于查找 - 如果查找成功,conFind
将是找到的范围。然后将原始Range的终点设置为找到的Range的终点并应用粗体格式。
注意:我更愿意同时创建一个布尔变量来保存 Find.Found 的成功,而不是测试 Range.Find.Found,因为根据我的经验,它更可靠。我保留了您所拥有的代码,但是...
Set CON = selection.Range
selection.ExtendMode = False
Set conFIND = CON.Duplicate
With conFind.Find
.Text = ". "
.Forward = False
.Wrap = wdFindStop
.Execute
End With
If conFind.Find.Found Then
CON.End = conFind.End
CON.Font.Bold = True
else
end if