VBA将锚点(超链接)添加到活动工作表

时间:2017-07-19 15:44:59

标签: vba

我正在尝试创建从活动工作表到Sheet1的超链接。除了锚点选项卡中的“地址”外,一切都很好用。我不确定我是否有正确的语法将活动表连接到sheet1。活动工作表每次都将始终具有不同的名称,因此需要将活动工作表的语法视为为其指定特定名称的原因。

设置rng =表格(“Sheet1”)。范围(“A50”)。结束(xlUp)。偏移(1,0) rng.Hyperlinks.Add anchor:= rng,Address:= ThisWorkbook.ActiveSheet,TextToDisplay:= UserForm2.TextBox4.Value

1 个答案:

答案 0 :(得分:1)

Sub CreateHLFromActiveSheetToSheet1()
    Set Rng = ActiveSheet.Range("A50").End(xlUp).Offset(1, 0)
    ActiveSheet.Hyperlinks.Add anchor:=Rng, Address:="", SubAddress:=Sheets("Sheet1").Name & "!A1", _
        ScreenTip:="Click to go to Sheet1", TextToDisplay:="Go To Sheet1"

End Sub

Sub CreateHLFromSheet1ToActiveSheet()
    Set WS = Sheet1
    Set Rng = WS.Range("A50").End(xlUp).Offset(1, 0)
    WS.Hyperlinks.Add anchor:=Rng, Address:="", SubAddress:=ActiveSheet.Name & "!A1", _
        ScreenTip:="Click to go to Sheet1", TextToDisplay:="Go To " & ActiveSheet.Name

End Sub