宏打开并转到隐藏表

时间:2017-03-16 20:37:30

标签: excel-vba vba excel

很抱歉,因为我对此非常陌生,并且尽我所能地拼凑起来。下面允许我通过输入框中的条目进入打开的工作表但我需要它打开隐藏的工作表然后转到它。再次,抱歉我的措辞不好,但非常感谢任何帮助。

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

1 个答案:

答案 0 :(得分: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