Link to home
Start Free TrialLog in
Avatar of spar-kle
spar-kleFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How can I create a hyperlink using VBA and Windows navigation?

I would like to create a hyperlink, say in cell A1, by running a macro that opens a Windows navigation panel.
In principle it would be exactly like right clicking a cell and clicking the hyperlink option.

I would like the macro to specify the cell that the hyperlink would be added to.
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Hi,

Something like this:
Sub CreateHyperLink()
Dim Ws As Worksheet
Dim Rng As Range
Set Ws = Worksheets("Sheet1")
Set Rng = Ws.Range("A1")

Rng.Parent.Hyperlinks.Add Anchor:=Rng, Address:="", SubAddress:="Sheet1!A5", TextToDisplay:="Click Here to go to A5"

    With Rng.Font
        .ColorIndex = xlAutomatic
        .Underline = xlUnderlineStyleNone
    End With

    With Rng.Characters(Start:=21, Length:=2).Font
        .Underline = xlUnderlineStyleSingle
        .Color = -4165632
    End With

End Sub

Open in new window

It will create hyperlink in Cell A1 of Sheet1 to go to Cell A5
Create-Hyper-Link.xlsm
Avatar of spar-kle

ASKER

Thanks Shuns.  I can see that will add a hyperlink according to the hard coding. However I want to click on a button ...open a navigation pane ...navigate to a file click on the file and create a link in a cell designated by the code.
Sorry "Shums"
ASKER CERTIFIED SOLUTION
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's excellent.
Thanks Shums
You're Welcome! Please to help