继续以 Find 方法开始的搜索。
命名空间:  Microsoft.Office.Tools.Excel
程序集:  Microsoft.Office.Tools.Excel(在 Microsoft.Office.Tools.Excel.dll 中)
语法
声明
Function FindPrevious ( _
    After As Object _
) As Range
Range FindPrevious(
    Object After
)
参数
- After
 类型:System.Object
 要在其之前搜索的单元格。此单元格就是从用户界面执行的搜索完成后处于活动状态的单元格。注意,After 必须为 XmlMappedRange 控件中的单个单元格。请记住,搜索将从该单元格之后开始;只有方法绕回到指定的单元格之后,才会搜索该单元格。如果未指定此参数,则搜索将在 XmlMappedRange 控件左上角的单元格之前开始。
返回值
类型:Microsoft.Office.Interop.Excel.Range
一个 Range,表示包含指定信息的单元格。
备注
查找与为 Find 方法指定的条件匹配的前一个单元格,并返回表示该单元格的 Range。
此方法不会影响选定内容或活动单元格。
可选参数
有关可选参数的信息,请参见Office 解决方案中的可选参数。
示例
下面的代码示例将 XmlMappedRange 的值设置为字符串“Smith”,然后使用 Find、FindNext 和 FindPrevious 方法查找第一个带有字符串“Smith”的单元格。 因为 XmlMappedRange 总是正好包含一个单元格,所以在每种情况下都会找到同一个单元格。 此代码示例假定当前工作表包含一个名为 CustomerLastNameCell 的 XmlMappedRange。
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
private void FindSmith()
{
    this.CustomerLastNameCell.Value2 = "Smith";
    // Use Find to get the range with "Smith".
    Excel.Range range1 = this.CustomerLastNameCell.Find("Smith",
        missing, missing, missing, missing, Excel.XlSearchDirection.xlNext,
        missing, missing, missing);
    string address1 = range1.get_Address(missing, missing,
        Excel.XlReferenceStyle.xlA1, missing, missing);
    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(missing, missing, 
        Excel.XlReferenceStyle.xlA1, missing, missing);
    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(missing, missing,
        Excel.XlReferenceStyle.xlA1, missing, missing);
    MessageBox.Show("FindPrevious method found the range: " + address3);
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。