1. 程式人生 > >一鍵生成目錄【excel】

一鍵生成目錄【excel】

Sub 建立並返回目錄()
    Dim i As Integer
        For i = 1 To Sheets.Count
            Sheets(1).Range("b" & 1 + i) = Sheets(i).Name
            Sheets(1).Range("b" & 1 + i).Select
            ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
            "'" & Sheets(i).Name & "'!a1", TextToDisplay:=Sheets(i).Name
            Sheets(i).Hyperlinks.Add Anchor:=Sheets(i).Range("G2"), Address:="", SubAddress:=Sheets("目錄").Name & "!A1", TextToDisplay:="返回目錄"
        Next
End Sub

  程式碼中的這個Range("G2")可以改動,比如你想在單元格A1建立返回目錄的超級連結,可以改成Range("A1")