excel中批量創建超鏈接代碼(連接當前文檔中的sheet),在sheet1中B列中要創建一系列的超鏈接,鏈接的內容是本文檔中的其他sheet,如下圖,在sheet1下創建宏,代碼如下。

Sub 宏1()
Dim temp, temp2
Dim i, j
j = 1
For i = 5 To 74
temp = "'G" & j & "'!A1"
temp2 = "G" & j
Range("B" & i).Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:=temp, TextToDisplay:="G" & j
j = j + 1
Next
End Sub
在每一個sheet的第一個單元格中創建返回sheet1的B列所對應的鏈接單元格。
Sub 宏2()
Dim temp, temp2, i, j
j = 1
For i = 5 To 74
temp = "sheet1!B" & i
temp2 = "G" & j
Sheets(temp2).Select
ActiveCell.FormulaR1C1 = ""
Range("A1").Select
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:=temp, TextToDisplay:="返回"
j = j + 1
Next
End Sub
