New! Excel User Group Now Open @ www.excelusergroup.org, Check It Out!


Adding hyperlinks to files in a folder

The example code below will add hyperlinks to the cells selected, allowing you, in this case', to open the Adobe Acrobat files in the folder C:\Images.  This will open them in Adobe Acrobat, if installed.

The code can be used for any file types by simply changing the extension in the code. As also noted, if the files have the extension actually in the cell text then this can be omitted entirely.

After the code is run, each cell will be a hyperlink, with the text in the cell set to the file name as will the tooltip. (The small pop-up when you hover over the text)

 

Sub SetHyperLinks()
Dim myCell As Range
Dim sFName As String
Const sPath = "C:\Images\"
For Each myCell In Selection
' Exclude & ".pdf" if extension in name
sFName = myCell.Value & ".pdf"
myCell.Hyperlinks.Add Anchor:=myCell, _
    Address:=sPath & sFName, _
        ScreenTip:="Open: " & sFName, _
            TextToDisplay:=sFName
Next myCell
End Sub

Top

Copyright Nick Hodge 2008. All Rights Reserved.