What does `Range.Hyperlink.Shape` do?

Viewed 50

I understand, that Shape.Hyperlink is the hyperlink associated with the shape and Shape.Hyperlink.Follow opens and displays the hyperlink in a web browser, the same as if I left-clicked on the shape.

Q: But what does the Range.Hyperlink.Shape do, when I assign some shape to it?

It seems to be a shape associated with the hyperlink....

Does it popup the Shape when I hover over the text of the hyperlink, or something else ?

For Gary's:

Sub DummySub(rng As Range, shp As Shape)               
   rng.Hyperlinks.Add rng, "http://microsoft.com", "", "Hint"
   rng.Hyperlinks(1).Shape = shp 
End Sub
1 Answers

For a sheet shape you can add a Link. Right clicking it or in VBA code. You can choose between Existing file or web Page, Place in this Document, Create new Document or E-mail-Address.

It becomes a hyperlink if you choose 'Existing file or web Page` and supply it a web page address.

But Range.Hyperlink.Shape does not have a meaning in VBA, I'm afraid...

The Hyperlink Range property does not exist in VBA. Only Hyperlinks. Hyperlink.Shape yes...

Please, test the next code:

Sub testRangeHiperlynk()
  Dim HypShape As Shape

    Set HypShape = ActiveSheet.Shapes.AddShape(msoShapeRoundedRectangle, 300, 160, 100, 20)
      HypShape.Name = "testRect"
    HypShape.TextFrame.Characters.text = "Go to Google"
    ActiveSheet.Hyperlinks.aDD Anchor:=HypShape, address:="http://www.google.com", SubAddress:="GoToGoogle!A1"
    Debug.Print ActiveSheet.Shapes("testRect").Hyperlink.Shape.Name
    ActiveSheet.Shapes("testRect").Hyperlink.Shape.Fill.ForeColor.RGB = RGB(255, 0, 0)
End Sub

It creates a rectangle, names it "textRect", writes something on it and then creates a (kind of) hyperlink in A1, but with reference to the newly created shape, targeting Google.com.

Then see what HypShape.Hyperlink.Shape.Name returns in Immediate window and how the shape defined using Hyperlink.Shape.Fill has been colored...

But Range.Hyperlink.Shape does not exist in VBA :)

Edited: The property can be used a little cleverer. Run this code (after the first one) and you will be able to set a shape based on the worksheet hyperlinks:

Sub testHypShape()
 Dim H As Hyperlink, sh As Shape
  For Each H In ActiveSheet.Hyperlinks
    If H.Shape.Name = "testRect" Then Set sh = H.Shape: Exit For
  Next
  sh.Fill.ForeColor.RGB = RGB(0, 225, 225)
End Sub
Related