2017-03-16 64 views
0

對不起,因爲我對此很新,並且可以拼湊一些我能做的事情。以下允許我通過輸入框中的條目轉到打開的工作表,但我需要打開隱藏的工作表然後轉到該工作表。再次,對我可憐的措辭感到抱歉,但任何幫助非常感謝。宏打開並轉到隱藏表

Sub SearchSheetName() 
    Dim sName As String 
    Dim sFound As Boolean 

    sName = InputBox(prompt:="Enter BAC to find in workbook:", Title:="Sheet search") 

    If sName = "" Then Exit Sub 
    sFound = False 

    On Error Resume Next 
     ActiveWorkbook.Sheets(sName).Select 
     If Err = 0 Then sFound = True 
    On Error GoTo 0 

    If sFound = False Then 
     MsgBox prompt:="The sheet '" & sName & "' No Data or Non Assigned Account!", Buttons:=vbExclamation, Title:="Search result" 
    End If 
End Sub 

回答

2
Sub SearchSheetName() 
    Dim sName As String, sht As Worksheet 

    sName = InputBox(prompt:="Enter BAC to find in workbook:", Title:="Sheet search") 

    If sName = "" Then Exit Sub 

    On Error Resume Next 
    Set sht = ActiveWorkbook.Sheets(sName) '<< try setting a reference... 
    On Error GoTo 0 

    If sht Is Nothing Then 
     'sheet not found... 
     MsgBox prompt:="The sheet '" & sName & _ 
      "' No Data or Non Assigned Account!", _ 
      Buttons:=vbExclamation, Title:="Search result" 
    Else 
     If sht.Visible = xlSheetHidden Then sht.Visible = xlSheetVisible 
     sht.Select 
    End If 

End Sub