0
votes

I'm currently building a work book with a few macros. Part of the macro I'm writing changes the sheet name to the value of the cell and then proceeds to generate the associated hyperlinks to other pages.

Is there a way I can create a hyperlink from the active sheet to the active sheet? I will then copy this cell and move it to the associated sheets.

Code:

Sub Hyperlink Test()

Range("H1").Select

ActiveSheet.Hyperlinks.Add Anchor:=Selection,Address(""),SubAddress:=_
ActiveSheet,TextToDisplay:=Range("B1").Value

End Sub

Code:

Sub Hyperlink Test()

Range("H1").Select

ActiveSheet.Hyperlinks.Add Anchor:=Selection,Address(""),SubAddress:=_
ActiveSheet,TextToDisplay:=Range("B1").Value

End Sub
1

1 Answers

1
votes

Select some cell.

This will create in the Selected cell a hyperlink to A1 in the same sheet:

Sub CreateHyperlink()
    Dim s As String

    With ActiveSheet
        s = .Name & "!A1"
        .Hyperlinks.Add Anchor:=ActiveCell, Address:="", SubAddress:=s, TextToDisplay:="Jump"
    End With
End Sub

EDIT#1:

If the worksheet name contains any space characters, then use this for s:

s = "'" & .Name & "'!A1"