将超链接添加到动态单元格

时间:2018-02-05 13:56:30

标签: excel vba hyperlink

我正忙着通过vba添加到单元格的超链接。我想我有预先要求添加超链接。虽然我无法让它工作。

通过浏览论坛等等,我能够创建这个代码,但无论我怎么努力,我都无法让它发挥作用。代码在Object required

上生成.Hyperlink
        With ActiveWorksheet

            .Hyperlink.Add Anchor:=ActiveWorksheet.Cells(i, 2)
            Address = Cells(SerialNumberLocation, 2)
            TextToDisplay = AlternateEngineNumber

        End With

有没有人有关于改进代码的任何提示?

ActiveWorkSheets更改为ActiveSheets并将.Hyperlink移至Hyperlink我仍然会收到相同的错误,代码为nwo,如

        With ActiveSheet

            Hyperlink.Add Anchor:=ActiveSheet.Cells(i, 2)_
            Address = Cells(SerialNumberLocation, 2)_
            TextToDisplay = AlternateEngineNumber

        End With

谢谢

1 个答案:

答案 0 :(得分:1)

这有效:

Sub dural()
    i = 1
    SerialNumberLocation = 9
    AlternateEngineNumber = "Hello"
    With ActiveSheet
                .Hyperlinks.Add Anchor:=.Cells(i, 2), _
                Address:=.Cells(SerialNumberLocation, 2).Value, _
                TextToDisplay:=AlternateEngineNumber
    End With
End Sub

请特别注意冒号期间

enter image description here