Hyperlink cell values to files

panterall

New Member
Joined
Jan 20, 2012
Messages
6
Hi,

Each week I receive a list in excel with over a 1000 of numeric values, which need to be [hyper]linked to different pdf files located inside the same folder [ "C:\folder\"].

Last time, I had to do them by hand and that was not fun at all :LOL:.
Could somebody please help me with a hint of VBA code to solve this issue?

My thinking goes like this:
1) I select the current cell
2) Compare the value of the cell with the values of the files inside that folder (the files are named with the same values listed in excel).
3) When a match is found, create a hyperlink displaying the value of the cell
4) Repeat the process again with a different value.

So, if you could help me get through this I will really appreciate it
Thank you!!
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
This is what I think you want

Code:
Sub SetUpHyper()
    Const sPath = "C:\Folder\"
    Const sSheet = "Sheet1"
    With Sheets(sSheet)
        For i = 0 To .Range("A" & Rows.Count).End(xlUp).Row - 1
            If Trim(.Range("A1").Offset(i, 0)) <> "" Then
                fn = Dir(sPath & .Range("A1").Offset(i, 0))
                If fn <> "" Then .Range("A1").Offset(i, 0).Hyperlinks.Add _
                            Anchor:=.Range("A1").Offset(i, 0), _
                            Address:=sPath & fn, TextToDisplay:=fn
            End If
        Next i
    End With
End Sub
 
Upvote 0
Hi tlowry,

Thank you very much!!! I just tweaked it a little bit, but it worked just fine. You just saved me hours of boring non-sense work.
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,273
Members
448,559
Latest member
MrPJ_Harper

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