XmlMappedRange.FindNext(Object) 方法

定义

public Microsoft.Office.Interop.Excel.Range FindNext (object After);
abstract member FindNext : obj -> Microsoft.Office.Interop.Excel.Range
Public Function FindNext (Optional After As Object) As Range

参数

After
Object

要在其之后搜索的单元格。 此单元格就是从用户界面执行的搜索完成后处于活动状态的单元格。 请注意, After 必须是 控件中的 XmlMappedRange 单个单元格。 请记住,搜索将从该单元格之后开始;只有方法绕回到指定的单元格之后,才会搜索该单元格。 如果未指定此参数,则从 XmlMappedRange 控件左上角中的单元格之后开始搜索。

返回

一个 Range,表示包含指定信息的单元格。

示例

下面的代码示例将 的值 XmlMappedRange 设置为字符串“Smith”,然后使用 FindFindNextFindPrevious 方法来查找字符串为“Smith”的第一个单元格。 由于 始终 XmlMappedRange 只包含一个单元格,因此在每种情况下都会找到相同的单元格。 此代码示例假定当前工作表包含名为 XmlMappedRangeCustomerLastNameCell的 。

private void FindSmith()
{
    this.CustomerLastNameCell.Value2 = "Smith";

    // Use Find to get the range with "Smith".
    Excel.Range range1 = this.CustomerLastNameCell.Find("Smith",
        Excel.XlSearchDirection.xlNext);
    string address1 = range1.get_Address(missing, missing,
        Excel.XlReferenceStyle.xlA1);
    MessageBox.Show("Find method found the range: " + address1);

    // Use FindNext to get the range with "Smith".
    Excel.Range range2 = this.CustomerLastNameCell.FindNext(range1);
    string address2 = range2.get_Address(
        Excel.XlReferenceStyle.xlA1);
    MessageBox.Show("FindNext method found the range: " + address2);

    // Use FindPrevious to get the range with "Smith".
    Excel.Range range3 = this.CustomerLastNameCell.FindPrevious(range2);
    string address3 = range3.get_Address(
        Excel.XlReferenceStyle.xlA1);
    MessageBox.Show("FindPrevious method found the range: " + address3);
}
Private Sub FindSmith()
    Me.CustomerLastNameCell.Value2 = "Smith"

    ' Use Find to get the range with "Smith".
    Dim range1 As Excel.Range = Me.CustomerLastNameCell.Find( _
        "Smith", SearchDirection:=Excel.XlSearchDirection.xlNext)
    Dim address1 As String = range1.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("Find method found the range: " & address1)

    ' Use FindNext to get the range with "Smith".
    Dim range2 As Excel.Range = Me.CustomerLastNameCell.FindNext(range1)
    Dim address2 As String = range2.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("FindNext method found the range: " & address2)

    ' Use FindPrevious to get the range with "Smith".
    Dim range3 As Excel.Range = Me.CustomerLastNameCell.FindPrevious(range2)
    Dim address3 As String = range3.Address(ReferenceStyle:=Excel.XlReferenceStyle.xlA1)
    MsgBox("FindPrevious method found the range: " & address3)
End Sub

注解

查找与为 Find 方法指定的条件匹配的下一个单元格,并返回表示 Range 该单元格的 。

此方法不会影响所选内容或活动单元格。

当搜索到达指定搜索范围的末尾时,它将环绕到范围的开头。 若要在发生此环绕时停止搜索,请保存第一个找到的单元格的地址,然后针对此保存的地址测试每个连续找到的单元格地址。

可选参数

有关可选参数的信息,请参阅 Office 解决方案中的可选参数

适用于