Excel VBA搜索特定工作表

时间:2014-07-01 09:50:08

标签: vb.net excel

我正在尝试在特定工作簿(CSI)中搜索特定工作表(CSI Tracker)。

我有以下代码:

Function FindAllOnWorksheets(InWorkbook As Workbook, _
            InWorksheets As String, "CSI Tracker", _
            SearchAddress As String, _
            FindWhat As Variant, _
            Optional LookIn As XlFindLookIn = xlValues, _
            Optional LookAt As XlLookAt = xlWhole, _
            Optional SearchOrder As XlSearchOrder = xlByRows, _
            Optional MatchCase As Boolean = False, _
            Optional BeginsWith As String = vbNullString, _
            Optional EndsWith As String = vbNullString, _
            Optional BeginEndCompare As VbCompareMethod = vbTextCompare) As Variant

任何帮助,将不胜感激。 感谢

1 个答案:

答案 0 :(得分:0)

此代码将遍历工作簿的工作表名称,如果该工作表存在,则会激活它。

Sub test()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets 'a specific workbook (CSI)
    If ws.Name = "CSI Tracker" Then
        ws.Activate
        Exit For
    End If
Next ws
End Sub

'你可以命名为Workbooks(“CSI.xls”)

Sub test()
Dim ws As Worksheet
Workbooks("Brief v13.xls").Activate
For Each ws In Workbooks("CSI.xls").Sheets
    If ws.Name = "CSI Tracker" Then
        ws.Activate
        Exit For
    End If
Next ws

End Sub