如何查看 MS Excel 中的所有工作表标签?

如何查看 MS Excel 中的所有工作表标签?

我有一个包含许多工作表的 MS Excel 文件,我需要移动到它们。

我如何列出所有标签并移动到特定标签?

答案1

很有趣。我刚刚写了三个宏,它们可以很好地完成这项工作。第一个宏生成一个摘要表(名为sh_摘要),然后选择它。然后,从这个新的摘要表中,选择所需的工作表名称之一(例如,选择单元格 A2),然后启动第二个宏,它将选择/导航到您选择的工作表。第三个宏将带您返回摘要表。第二个和第三个宏应该被快捷键化,以便快速导航。

1:

Sub findSheets()
    Dim sheetNum As Integer
    Dim i As Integer
    Dim theSh(999)

    'count sheets:
    sheetNum = ActiveWorkbook.Worksheets.Count

    'check for a summary sheet and delete it if found:
    For i = 1 To sheetNum
        If ActiveWorkbook.Worksheets(i).Name = "sh_summary" Then
            Application.DisplayAlerts = False
            ActiveWorkbook.Worksheets(i).Delete
            Application.DisplayAlerts = True
        End If
    Next i

    'count sheets again:
    sheetNum = ActiveWorkbook.Worksheets.Count

    'get sheet names
    For i = 1 To sheetNum
        theSh(i) = ActiveWorkbook.Worksheets(i).Name
    Next i

    'create summary sheet:
    Sheets.Add After:=Sheets(Sheets.Count)
    Sheets(Sheets.Count).Select
    Sheets(Sheets.Count).Name = "sh_summary"

    'print sheet names on summary sheet:
    For i = 1 To sheetNum
        Cells(1, 1).Value = "Worksheet summary:"
        Cells((1 + i), 1).Value = theSh(i)
    Next i
End Sub

2:

Sub navToSheet()
    On Error Resume Next
    ActiveWorkbook.Worksheets(ActiveCell.Value).Select
    If Err.Number <> 0 Then
        MsgBox "Can't find sheet - select and try again."
        Err.Clear
    End If
End Sub

3:

Sub navToSummary()
    On Error Resume Next
    ActiveWorkbook.Worksheets("sh_summary").Select
    If Err.Number <> 0 Then
        MsgBox "Can't find summary sheet."
        Err.Clear
    End If
End Sub

相关内容