VBA Hyperlink Debugging

Peteor

Board Regular
Joined
Mar 16, 2018
Messages
136
Hey everyone. I am currently working on Debugging a code that has worked wonders for me for the last 10 years. Here is my code:

1 Worksheets(1).Select
2 R = Range("A65536").End(xlUp).Row
3 For Each Cell In Range("A2:A" & R)
4 Cell.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=False
5 Next Cell
6 CopyTargetBookmark = 1
7 For Each Workbook In Application.Workbooks

It is getting hung up on line 4 with a run-time error 9 "Subscript is out of range". ANY input would be invaluable.

Thank you,
Peter
 

Some videos you may like

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,602
Try changing the Follow line to:
Code:
        If Cell.Hyperlinks.Count > 0 Then Cell.Hyperlinks(1).Follow NewWindow:=False, AddHistory:=False
 

Peteor

Board Regular
Joined
Mar 16, 2018
Messages
136
You are a gentleman and a scholar. Worked like a charm. Never thought to try an If Then structure.
 

Peteor

Board Regular
Joined
Mar 16, 2018
Messages
136
So I have found what has been causing my problem.

What this code does:
It takes information from LOTS of workbooks, and concatenates the useful information into 1 workbook (it is much longer than shown above).

The Problem:
Either via a bug or deliberate implementation, Microsoft has decided the "Cell.Hyperlinks(1).Follow" function should not work for code generated hyperlinks. It does work for manually generated hyperlinks. It even works if I decide to use F8 and step through my code "manually".

The Question:
Is there a work around or subroutine anyone knows of or has written that circumvents the problem? I.E. Is there a way to automatically open code generated hyperlinks other than the "Cell.Hyperlinks(1).Follow" function?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,165
Messages
5,594,622
Members
413,918
Latest member
Mikey_C

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
Top