Problem with Hyperlinking VBA Code

keeegs

Board Regular
Joined
Sep 25, 2011
Messages
145
Hi Guys

my code goes through a range and checks to see if there are 2 files relating to the entry and adds a hyperlink.
It all works fine, cept one little thing.

It adds a hyperlink to the cell before the range ("A3") and gives it links that the last cell gets.

Any ideas why its hyperlinking a cell that isnt even in the range?

Thanks, Keegan

Code:
For Each CL In Workbooks(INV).Sheets("Specs").Range("A4:A" & Workbooks(INV).Sheets("Specs").Range("A65536").End(xlUp).Row)
File = CL
Desc = CL.Offset(0, 1)
folder = CL.Offset(0, 2)
If folder = "Packaging" Then
folder = CL.Offset(0, 3)
End If
folder = folder & "\"
MyFile = Dir(MyPath & Spec & folder & File & ".pdf")
If MyFile = File & ".pdf" Then
    CL.Hyperlinks.Add _
        Anchor:=Selection, _
        Address:=MyPath & Spec & folder & File & ".pdf", _
        TextToDisplay:=File
    Else
    CL.Hyperlinks.Delete
    CL = File
    End If
   
MyFile = Dir(MyPath & Art & folder & File & ".pdf")
If MyFile = File & ".pdf" Then
    CL.Offset(0, 1).Hyperlinks.Add _
        Anchor:=Selection, _
        Address:=MyPath & Art & folder & File & ".pdf", _
        TextToDisplay:=Desc
    Else
    CL.Offset(0, 1).Hyperlinks.Delete
    CL.Offset(0, 1) = Desc
    End If
    
Next CL
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try
Code:
[FONT=Consolas][SIZE=2][COLOR=Navy]Sheets("Specs").Hyperlinks.Add Anchor:=CL,…[/COLOR][/SIZE][/FONT]
instead of
Code:
[FONT=Consolas][SIZE=2][COLOR=Navy]CL.Hyperlinks.Add Anchor:=Selection,…[/COLOR][/SIZE][/FONT]
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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