Create hyperlinks for selected cells

Bagsy

Active Member
Joined
Feb 26, 2005
Messages
467
Office Version
  1. 365
Platform
  1. Windows
Hi I wonder if anybody can help on this, I have a register which in column A holds a unique certificate number. I then have to RH click and create a hyperlink to the PDF cert with the same number in a folder "L:\MATERIALS\Material Certification\03-PLATE"
I am trying to get some code to work so I can select a bunch of these cells in column A and create hyperlinks to each selected cell automatically.
I have something wrong because it is skipping the line of code below
VBA Code:
ActiveSheet.Hyperlinks.Add Anchor:=c, Address:=p & s, TextToDisplay:=c.Value
Full code below
Any help is much appreciated
Code:
Sub InsertHyperlinks()
Const p = "L:\MATERIALS\Material Certification\03-PLATE"
Dim c As Range
Dim s As String
Selection.Hyperlinks.Delete
For Each c In Selection
s = Dir(p & c.Value & ".pdf")
If s <> "" Then
ActiveSheet.Hyperlinks.Add Anchor:=c, Address:=p & s, TextToDisplay:=c.Value
End If
Next c
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Is 03-PLATE a folder or part of the filename?
 
Upvote 0
Hi Fluff, thanks for getting back to me 03-PLATe is a folder
 
Upvote 0
In that case you need to add a \ to the end of the path
VBA Code:
Const p = "L:\MATERIALS\Material Certification\03-PLATE\"
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,973
Members
449,059
Latest member
oculus

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