简体   繁体   English

Excel VBA为活动单元格创建超链接

[英]Excel VBA to make hyperlink for active cell

I want to make a link from active cell in workbook 1 which can I use it in workbook 2. I use the following code which assigned to a button: 我想从工作簿1中的活动单元格建立链接,可以在工作簿2中使用它。我使用分配给按钮的以下代码:

 With ActiveSheet
   .Hyperlinks.Add Range("F6"), _
      .Parent.FullName & "#'" & .Name & "'!" & "$A$1", TextToDisplay:="link"
 End With

This code made a link with full path and I can use it in any workbook but I need some changes which I could to: 这段代码建立了一个具有完整路径的链接,我可以在任何工作簿中使用它,但是我需要做一些更改,以便:

  1. Make the active cell hyperlink not cell A1 which specified in code. 使活动单元格超链接不是代码中指定的单元格A1。
  2. The value in the active cell become text to display arg of hyperlink function. 活动单元格中的值将变为文本,以显示超链接功能的arg。

Thanks 谢谢

PS after Vityata answere: how can i change Range("F6") to activecell adress? Vityata回答后的PS:如何将Range(“ F6”)更改为Activecell地址?

In order to obtain the active cell value and address, change your code the corresponding places with the following: 为了获得活动单元格的值和地址,请使用以下命令将代码更改为相应的位置:

ActiveCell.Address
ActiveCell.Value

I find it just to close this topic. 我发现它只是为了关闭本主题。

Sub Button36_Click()
Dim newRange As Range
Set newRange = Range(ActiveCell, ActiveCell.Offset(numRows, numCols))
     With ActiveSheet
   .Hyperlinks.Add Anchor:=newRange, _
      Address:=.Parent.FullName & "#'" & .Name & "'!" & ActiveCell.Address, TextToDisplay:=ActiveCell.Text
      End With
End Sub

try this 尝试这个

Sub add_links_Input_Column()
Dim lRow As Long
Dim ColHead As String

ColHead = InputBox("Enter Column Letter", "Identify Column", [c1].Value)
If ColHead = "" Then Exit Sub

    With ActiveSheet
        lRow = .Range(ColHead & .Rows.Count).End(xlUp).Row
        For Each c In .Range(ColHead & "2:" & ColHead & lRow)
            ActiveSheet.Hyperlinks.Add anchor:=c, Address:=c.Value
        Next
    End With

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM