1
我在名爲「索引」的工作表的A列中列出了100多個工作表名稱。每個工作表名稱自然對應於我的工作簿中的工作表。如何爲VBA中的所有工作簿工作表創建超鏈接的目錄表?
如何超鏈接出現在「索引」中的每個工作表名稱,以便通過單擊鏈接可以簡單訪問每個相應工作表?
我在名爲「索引」的工作表的A列中列出了100多個工作表名稱。每個工作表名稱自然對應於我的工作簿中的工作表。如何爲VBA中的所有工作簿工作表創建超鏈接的目錄表?
如何超鏈接出現在「索引」中的每個工作表名稱,以便通過單擊鏈接可以簡單訪問每個相應工作表?
欲瞭解更多詳情,請參閱我的答案在這裏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