Adding hyperlink "comments" to shapes with vba

akramer08

Active Member
Joined
May 2, 2012
Messages
265
I have a macro that creates a series of connector arrows. I needed a way to add a mouseover comment to the arrows. I just added a hyperlink that if clicked will just put them on the same page, but I added a screentip to it and its exactly what I need. But, each time the macro runs, it will delete all existing arrows then add new arrows connecting different shapes, so the hyperlink and comment will be erased. Any way to add a hyperlink with a screentip to a shape with VBA? Below is my code that adds the arrow.

Code:
    With Worksheets(1).Shapes.AddConnector(msoConnectorStraight, 0, 0, 100, 100)
        With .ConnectorFormat
            .BeginConnect ActiveSheet.Shapes(City1), 1
            .EndConnect ActiveSheet.Shapes(City2), 1
        End With
        .RerouteConnections


        .Line.Weight = 0.75
        .Line.DashStyle = msoLineSolid             'msoLineDash for dashed
        .ConnectorFormat.Type = msoConnectorStraight
        .Line.Style = msoLineSingle
        .Line.Transparency = 0#
        .Line.Visible = msoTrue
        .Line.ForeColor.SchemeColor = 10         '17 for green
        .Line.BackColor.RGB = RGB(255, 255, 255)
        .Line.BeginArrowheadLength = msoArrowheadLengthMedium
        .Line.BeginArrowheadWidth = msoArrowheadWidthMedium
        .Line.BeginArrowheadStyle = msoArrowheadNone
        .Line.EndArrowheadLength = msoArrowheadLengthMedium
        .Line.EndArrowheadWidth = msoArrowheadWidthMedium
        .Line.EndArrowheadStyle = msoArrowheadTriangle
    End With
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Let me know if this works for you.

Code:
    Dim shp As Shape


    With Worksheets(1)
        Set shp = .Shapes.AddConnector(msoConnectorStraight, 0, 0, 100, 100)
        With shp
            With .ConnectorFormat
                .BeginConnect ActiveSheet.Shapes(City1), 1
                .EndConnect ActiveSheet.Shapes(City2), 1
            End With
            .RerouteConnections
            .Line.Weight = 0.75
            .Line.DashStyle = msoLineSolid             'msoLineDash for dashed
            .ConnectorFormat.Type = msoConnectorStraight
            .Line.Style = msoLineSingle
            .Line.Transparency = 0#
            .Line.Visible = msoTrue
            .Line.ForeColor.SchemeColor = 10         '17 for green
            .Line.BackColor.RGB = RGB(255, 255, 255)
            .Line.BeginArrowheadLength = msoArrowheadLengthMedium
            .Line.BeginArrowheadWidth = msoArrowheadWidthMedium
            .Line.BeginArrowheadStyle = msoArrowheadNone
            .Line.EndArrowheadLength = msoArrowheadLengthMedium
            .Line.EndArrowheadWidth = msoArrowheadWidthMedium
            .Line.EndArrowheadStyle = msoArrowheadTriangle
        End With
        .Hyperlinks.Add Anchor:=shp, Address:="", SubAddress:="A1", ScreenTip:="Enter comment here"
    End With
 
Upvote 0
Here you go.

Code:
    Dim shp As Shape


    With Worksheets(1)
        Set shp = .Shapes.AddConnector(msoConnectorStraight, 0, 0, 100, 100)
        With shp
            With .ConnectorFormat
                .BeginConnect ActiveSheet.Shapes(1), 1
                .EndConnect ActiveSheet.Shapes(2), 1
            End With
            .RerouteConnections
            .Line.Weight = 0.75
            .Line.DashStyle = msoLineSolid             'msoLineDash for dashed
            .ConnectorFormat.Type = msoConnectorStraight
            .Line.Style = msoLineSingle
            .Line.Transparency = 0#
            .Line.Visible = msoTrue
            .Line.ForeColor.SchemeColor = 10         '17 for green
            .Line.BackColor.RGB = RGB(255, 255, 255)
            .Line.BeginArrowheadLength = msoArrowheadLengthMedium
            .Line.BeginArrowheadWidth = msoArrowheadWidthMedium
            .Line.BeginArrowheadStyle = msoArrowheadNone
            .Line.EndArrowheadLength = msoArrowheadLengthMedium
            .Line.EndArrowheadWidth = msoArrowheadWidthMedium
            .Line.EndArrowheadStyle = msoArrowheadTriangle
        End With
        .Hyperlinks.Add Anchor:=shp, Address:="", SubAddress:="A1", ScreenTip:=.Range("Z3").Value
    End With
 
Upvote 0
Try the following.

Code:
    Dim shp As Shape


    With Worksheets(1)
        Set shp = .Shapes.AddConnector(msoConnectorStraight, 0, 0, 100, 100)
        With shp
            With .ConnectorFormat
                .BeginConnect ActiveSheet.Shapes(City1), 1
                .EndConnect ActiveSheet.Shapes(City2), 1
            End With
            .RerouteConnections
            .Line.Weight = 0.75
            .Line.DashStyle = msoLineSolid             'msoLineDash for dashed
            .ConnectorFormat.Type = msoConnectorStraight
            .Line.Style = msoLineSingle
            .Line.Transparency = 0#
            .Line.Visible = msoTrue
            .Line.ForeColor.SchemeColor = 10         '17 for green
            .Line.BackColor.RGB = RGB(255, 255, 255)
            .Line.BeginArrowheadLength = msoArrowheadLengthMedium
            .Line.BeginArrowheadWidth = msoArrowheadWidthMedium
            .Line.BeginArrowheadStyle = msoArrowheadNone
            .Line.EndArrowheadLength = msoArrowheadLengthMedium
            .Line.EndArrowheadWidth = msoArrowheadWidthMedium
            .Line.EndArrowheadStyle = msoArrowheadTriangle
        End With
        .Hyperlinks.Add Anchor:=shp, Address:="", SubAddress:="A1", ScreenTip:=.Range("Z3").Text
    End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,661
Messages
6,173,647
Members
452,525
Latest member
DPOLKADOT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top