Auto Hyperlink

ateebali

Board Regular
Joined
Dec 13, 2018
Messages
108
I have a workbook name "TCS" I want a vb code which apply on sheet1
It has range A2:A50 and have names in each cell
same name files are available on this sub folder;
Thisworkbook.path/Backup

For example, File name ABC on cell A1 should be hyperlink with file "ABC.xls" in folder
Cell A2 named XYZ should be hyperlink with file "XYZ.xlsb"
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
try this

Place in a standard module in file TCS
Code:
Sub AddLinks()
    Application.ScreenUpdating = False
    On Error Resume Next
    Dim cel As Range, fPath As String, x As Integer, f As Object, fldr As Object, FSO As Object
    Dim celName As String, matchName As String
    fpath = ThisWorkbook.Path & "\Backup"
    
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set fldr = FSO.GetFolder(fPath)
        For Each cel In Sheets("Sheet1").Range("A2:A50")
            celName = cel.Value
            For Each f In fldr.Files
                matchName = Left(f.Name, InStrRev(f.Name, ".") - 1)
                If celName = matchName Then
                    ActiveSheet.Hyperlinks.Add cel, f.Path
                    Exit For
                End If
            Next f
        Next cel
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,269
Members
452,628
Latest member
dd2

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