0

I'm stuggaling with getting to grips with adding hyperlinks to cells through vba. I think I have the pre-requists for adding of hyperlinks. Although I'm unable to get it to work.

Having looked through forums and the such, I was able to create this code, but no matter how hard I try I am unable to get it to work. The code produces Object required on the .Hyperlink line

        With ActiveWorksheet

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

        End With

Do anyone have any tips on imporving the code?

By changing ActiveWorkSheets to ActiveSheets and removing the .Hyperlink to Hyperlink I still recive the same error, with the code nwo looking like

        With ActiveSheet

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

        End With

Thanks

12
  • It is Hyperlinks.Add and you need line continuation characters for a statement that is spread over more than one line. Commented Feb 5, 2018 at 13:58
  • With ActiveSheet Commented Feb 5, 2018 at 13:59
  • ... line continuations and commas. (If, however ,this is not your real code, then you can see the issues that arise when you don't post exactly.) Commented Feb 5, 2018 at 14:02
  • @Gary'sStudent I've change to what you said although, i still get the same error Commented Feb 5, 2018 at 14:10
  • @AndyG I've posted the code as it is in the macro. Not quite sure what your getting at with Line coninuations character, do you mean things like _)?? Commented Feb 5, 2018 at 14:11

1 Answer 1

1

This works:

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

Please take special notice of the colons and the periods

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.