hyperlinking a list of file names in excel

Rishm

New Member
Joined
Jun 30, 2021
Messages
14
Office Version
  1. 365
Platform
  1. Windows
I have a list of files below in my screenshot that I want to hyperlink. They all belong under the same folder. I am very new to VBA so I am struggling with this. They are all hyperlinked but all of the links lead to the last file "Zttach.xlsx". Is it possible to hyperlink all these files that belong to the same folder with just one macro?

linksoffiles.jpg



VBA Code:
Sub hyper()
Dim cell
For Each cell In Selection
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="C:\Users\risha\Downloads\a_few_little_tests\New folder\" & cell
Next cell
End Sub
Code:
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Hi Rishm,

with the codeline
Code:
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="C:\Users\risha\Downloads\a_few_little_tests\New folder\" & cell
you add the same link to every cell because you used
Code:
Anchor:=Selection
Maybe alter the code and try
Code:
Sub hyper_corr()
Dim cell As Range
For Each cell In Selection
  ActiveSheet.Hyperlinks.Add _
      Anchor:=cell, _
      Address:="C:\Users\risha\Downloads\a_few_little_tests\New folder\" & cell
Next cell
End Sub
You should think about replacing Selection where you would need to mark the area to work on before starting the macro with something like
Code:
Sub hyper_corr2()
Dim cell As Range
On Error Resume Next
For Each cell In ActiveSheet.UsedRange.Columns(1).SpecialCells(xlCellTypeConstants)
  ActiveSheet.Hyperlinks.Add _
      Anchor:=cell, _
      Address:="C:\Users\risha\Downloads\a_few_little_tests\New folder\" & cell
Next cell
If Err <> 0 Then
  MsgBox "Please check the range to work on, no constants found in Column A of active sheet"
End If
End Sub
or
Code:
...
For Each cell In Range("A1", Cells(Rows.Count, "A").End(xlUp))
...
The first code will work on all cells in Column A on the active sheet which are filled with constants, the sniplet will build a dynamic range with all filled cells in Column A where you might like to add a check if the cells are filled.

Ciao,
Holger
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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