Macro to create hyperlink

J

JoeP

I have cells in an Excel 2003 spreadsheet that contains the path to a file. I
would like to create a macro that takes the content of an active cell (that
has a path to a file) and convert it to a hypelink to that file.
Any help would be appreciated.
 
K

Kevin Smith

Hello,

this works on the activecell

Dim MyHyper As String
MyHyper = ActiveCell.Value
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
MyHyper, TextToDisplay:=MyHyper

or if you wanted to, you could specify the cell by

Dim MyHyper As String
range("A1").select
MyHyper = ActiveCell.Value
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:= _
MyHyper, TextToDisplay:=MyHyper

hope that helps.
 
M

Mike H

Hi,

The 'macro' to do this is a one-liner. If you have lots of these then its
posible to loop through them

Sub addlinks()
ActiveSheet.Hyperlinks.Add Anchor:=Selection, _
Address:=Selection.Text
End Sub


Mike
 
S

Simon Lloyd

This is for every cell in a range but you can adapt it!


Code:
--------------------
Dim Rng As Range, MyCell As Range
Set Rng = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
For Each MyCell In Rng
If MyCell <> "" Then
MyCell.Hyperlinks.Add Anchor:=Range(MyCell.Address), Address:=MyCell.Text, TextToDisplay:=MyCell.Text
End If
Next MyCell
--------------------


JoeP;478050 said:
I have cells in an Excel 2003 spreadsheet that contains the path to a
file. I
would like to create a macro that takes the content of an active cell
(that
has a path to a file) and convert it to a hypelink to that file.
Any help would be appreciated.


--
Simon Lloyd

Regards,
Simon Lloyd
'Microsoft Office Help' (http://www.thecodecage.com)
 
Top