VBA code for finding matching files and add hyperlink

papplaszlodaniel

New Member
Joined
May 13, 2014
Messages
10
Hi there,


I have the list of file names in Excel (MS Excel 2013) without extensions (such as ".pdf").
I would like to have a macro which if finds a file with a matching file name (in a given folder), it hyperlinks it to the matching Excel cell.


E.g.:

In Excel, column B contains the following list:

[TABLE="class: grid, width: 100"]
<tbody>[TR]
[TD]File names[/TD]
[/TR]
[TR]
[TD]B2[/TD]
[/TR]
[TR]
[TD]B3[/TD]
[/TR]
[TR]
[TD]B4[/TD]
[/TR]
[TR]
[TD]B5[/TD]
[/TR]
[TR]
[TD]B6[/TD]
[/TR]
</tbody>[/TABLE]

In a folder there are the following files:

B2.pdf
B3.pdf
D444.pdf
B5.pdf
B6.pdf

So after running the macro, it links the matching ones to the relevant cells (and does nothing when it doesn't find exact matches):

[TABLE="class: grid, width: 100"]
<tbody>[TR]
[TD]File names[/TD]
[/TR]
[TR]
[TD]B2[/TD]
[/TR]
[TR]
[TD]B3[/TD]
[/TR]
[TR]
[TD]B4[/TD]
[/TR]
[TR]
[TD]B5[/TD]
[/TR]
[TR]
[TD]B6[/TD]
[/TR]
</tbody>[/TABLE]


It would be the best if when running the macro, a window would pop up to select the folder where the macro should check the files.
 
Last edited:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,223,246
Messages
6,170,996
Members
452,373
Latest member
TimReeks

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