在下面的 While 循环中,我需要创建一个 Range 对象,其 Start 和 End 属性指示“whatever”的当前实例,以便我可以将其传递给某个例程。
此信息不在 ActiveDocument.Range 的 Start 和 End 属性中,而且我还没有在 Find 对象中识别它。我应该去哪里寻找?
Sub FindWhatever()
With ActiveDocument.Range
With .Find
.Wrap = wdFindStop
.Text = "whatever"
End With
Do While .Find.Execute = True
'??? Create a Range object indicating this instance of "whatever" ???
'Pass this Range object to a certain routine
.Collapse wdCollapseEnd
Loop
End With
End Sub
请尝试一下。
Sub FindWhatever()
Dim Rng As Range
Set Rng = ActiveDocument.Content
With Rng
With .Find
.Wrap = wdFindStop
.Text = "whatever"
End With
Do While .Find.Execute = True
' Rng is the object of search result
Rng.Select ' Testing
Stop
.Collapse wdCollapseEnd
Loop
End With
End Sub