2014-07-01 101 views
-1

我試圖在特定工作簿(CSI)中搜索特定工作表(CSI Tracker)。Excel VB搜索特定工作表

我有下面的代碼:

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 

任何幫助,將不勝感激。 謝謝

回答

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 

「你可以命名爲工作簿( 「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 

末次