I have a spreadsheet which contain several hyperlinks, some of which are from shapes. I am trying to loop through them, to see where each of them point in order to later remove some of them. For the hyperlinks contained in cells the following loop has worked:
Sub a()
Dim ws As Worksheet, hl As Hyperlink, o As Shape
For Each ws In Worksheets
For Each hl In ws.Hyperlinks
Debug.Print hl.Address
Next
Next
End Sub
But that seems to skip all the hyperlinks originating from shapes or other objects.
Is there any way I can loop through those as well? I have tried stuff like:
Sub a()
Dim ws As Worksheet, hl As Hyperlink, o As Shape
For Each ws In Worksheets
For Each o In ws.Shapes
For Each hl In o.Hyperlinks
Debug.Print hl.Address
Next
Next
Next
End Sub
But that gives me a runtime error 91 on the debug.print
line. Googling gives me nothing. So, have any of you got an idea of how to print the addresses?
A Shape doesn't have a
.Hyperlinks
property, only a.Hyperlink
one and you'll get an error from it if there is no associated hyperlink, so you need an error handler. For example: