【问题标题】:How do I create a hyperlinked table of contents for all of my workbook sheets in VBA?如何在 VBA 中为我的所有工作簿工作表创建超链接目录?
【发布时间】:2015-10-16 03:41:34
【问题描述】:

我在名为“索引”的工作表的 A 列中有一个包含 100 多个工作表名称的列表。每个工作表名称自然对应于我的工作簿中的一个工作表。

如何为出现在“索引”中的每个工作表名称提供超链接,以便我可以通过单击链接轻松访问每个相应的工作表?

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    更多详情请看我的回答List all sheets with link

    Sub CreateLinksToAllSheets()
    Dim sh As Worksheet
    Dim sh2 As Worksheet
    Dim cell As Range
    Dim lRow As Long
    
        'This is the sheet we will add the links to
        Set sh = ActiveWorkbook.Sheets("Sheet1")
        lRow = 1
    
        'Loop each sheet
        For Each sh2 In ActiveWorkbook.Worksheets
    
            'Make sure we are not on the current sheet or a sheet named 
            ' something we don't want to create a link for.
            If ActiveSheet.name <> sh2.name AND sh2.name <> "new customer" AND sh2.name <> "old archive" Then
    
                'Make sure we don't have a single quote in the sheet name.
                strLink = sh2.name
                If InStr(strLink, "'") Then
                    strLink = Replace(strLink, "'", "''")
                End If
    
                'Create a hyperlink to that sheet.
                sh.Hyperlinks.Add Anchor:=sh.Range("A" & lrow), Address:="", SubAddress:="'" & strLink & "'" & "!A1", TextToDisplay:=sh2.name
    
                lRow = lRow + 1
    
            End If
    
        Next sh2
    
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 2016-09-18
      • 2021-01-05
      • 1970-01-01
      • 2015-07-18
      相关资源
      最近更新 更多