Macro Hyperlink Code to File

ineedsomehelp89

New Member
Joined
Sep 28, 2011
Messages
2
I have an excel spreadsheet with over 500 rows and 10 columns. One of the columns contains filenames such as 1-14.PDF I also have a folder called E:\Pinnacle\This\Here which contains PDFs such as 1-14 I need a macro code to automatically turn each cell that has text like 1-14.PDF into a hyperlink to the actual file 1-14 in the folder. This needs to automatically do this for the whole column M. I have looked all over this board and internet for how to do it and cannot find it. I have found bits and pieces from codes like it but cannot seem to get it to work. Please help. This is my first spreadsheet like this but will be doing this on a daily basis for atleast a month. You would save me so much time.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
I believe you should be able to set the "Hyperlink Base" (see Excel help) to the folder you mentioned and then fill the "Hyperlink" function down the column adjacent to the filename using the filename as the argument to the function.

Gary
 
Upvote 0
We need it to be on that column

The end user will not understand if there are two columns with the filenames but only one of them is a hyperlink. Thank you for the help so far.
 
Upvote 0
You can hide the column that is not linked or possibly even put the filenames on a different sheet and hide the second sheet.

Gary
 
Upvote 0
Here's some code you can try if you're not satisfied with the hyperlink function.

Gary

In a standard module:

Code:
Public Sub Links()

Dim lLastRow As Long
Dim oTarget As Range
Dim oCell As Range
Dim sPath As String

'Change path to suit - trailing backslash required
sPath = "E:\Pinnacle\This\Here\"

'Last used row in column M
lLastRow = ActiveSheet.Range("M" & Rows.Count).End(xlUp).Row ' Change column to suit

Set oTarget = ActiveSheet.Range("M2:M" & lLastRow) ' Change column to suit

oTarget.Hyperlinks.Delete

For Each oCell In oTarget
    'Check for existing file
    If Dir(sPath & oCell.Text) <> "" Then
        ActiveSheet.Hyperlinks.Add oCell, sPath & oCell.Text, , , oCell.Text
    Else
        'Red interior if file not found
        oCell.Interior.ColorIndex = 3
    End If
Next oCell

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,176
Members
452,893
Latest member
denay

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