创建新工作表时创建超链接

时间:2018-07-19 08:09:47

标签: excel vba

我在互联网上找到VBA代码。它使用我的模板基于摘要工作表中的列表创建工作表。

我希望它与列表中的工作表建立超链接。

Mal=Template
Sammendrag=Summary

这里是:

Sub CreateSheetsFromAList() ' Example Add Worksheets with Unique Names

Dim MyRange As Range, i As Long
Dim ShtName As String

Application.ScreenUpdating = 0
With Sheets("Sammendrag")
    Set MyRange = .Range("B10:B69" & .Range("a" & .Rows.Count).End(xlUp).Row)
End With

Sheets("Mal").Visible = True

With MyRange
    For i = 1 To .Rows.Count
        ShtName = Trim(.Cells(i, 1).Value)
        If Len(ShtName) Then
            If Not WorksheetExists(ShtName) Then
                Sheets("Mal").Copy After:=Sheets(Sheets.Count)
                ActiveSheet.name = ShtName
            End If
        End If
    Next
End With

Sheets("Mal").Visible = False
Application.ScreenUpdating = 1

End Sub

1 个答案:

答案 0 :(得分:0)

使用此代码,您可以添加超链接:

.Cells(i, 1).Hyperlinks.Add Anchor:=.Cells(i, 1), Address:="", SubAddress:="'" & Worksheets(SHtName).Name & "'!A1", TextToDisplay:=Worksheets(SHtName).Name

点击后,您将跳至工作表的单元格A1。

相关问题