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

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
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,791
Messages
6,126,930
Members
449,349
Latest member
Omer Lutfu Neziroglu

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