Add Hyperlink to Cell

R

ryguy7272

I'm trying to point to files and add a hyperlink to each cell. This is my
code.
Sub FindFiles()
Dim rng As Range
Dim lRow As Long
Dim Filename As Variant
Filename = Application.GetOpenFilename(FileFilter:="Excel File
(*.xls),*.xls", MultiSelect:=True)
If TypeName(Filename) <> "Boolean" Then
Range("A1").Resize(UBound(Filename, 1) - LBound(Filename, 1) + 1).Value =
Application.Transpose(Filename)
End If

lRow = Range("A65536").End(xlUp).Row
Set rng = Range("A1:A" & lRow)
For Each c In rng
c.Hyperlinks.Add
Next

End Sub

It fails here:
c.Hyperlinks.Add

Any idea why?

Thanks,
Ryan---
 
J

Jacob Skaria

Hi Ryan

Replace the below code
lRow = Range("A65536").End(xlUp).Row
Set rng = Range("A1:A" & lRow)
For Each c In rng
c.Hyperlinks.Add
Next

with

Dim lngRow As Long, lngLastRow As Long
lngLastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
For lngRow = 1 To lngLastRow
ActiveSheet.Hyperlinks.Add Range("A" & lngRow), Range("A" & lngRow)
Next

'If it is not the activesheet specify the sheet name...

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top