0

I have a snippet of vba that should change the background colour of an auto generated hyperlink when the link is clicked (and doesn't produce an error

This is what should happen

Is this a link?
No? Ignore. Yes? Carry on

Does this link go anywhere?
No? Change background colour. Yes? Carry on

Repeat for every selected link

My code is as such:

    Sub Click_Links()

    Dim links As Hyperlink
    Dim rng As Range
    Set rng = Range("Range1")

' i = 0
On Error Resume Next
' n = 1 / i
If Err.Number <> 0 Then
'If there are no errors'

links.Parent.Interior.Color = 100
'Change bg colour'
   '  On Error Resume Next

Else
    On Error GoTo 0
    For Each links In rng.Hyperlinks
    'Every Line'
    links.Follow
    'Click the link'
     Next links
     'Go to next link to check'


End If
End Sub

When I run the script, nothing happens except the screen flickers. While messing with the code, I had issues with the End If but it basically magically dissapeared? before THAT, the script ran, changed one background colour and then stopped working straight after

Any help would be greatly appreciated!

Thank you

Luuklag
  • 3,897
  • 11
  • 38
  • 57
Badja
  • 857
  • 1
  • 8
  • 33
  • 1
    You DIM i and n, but don't use their values. You loop through a selection, but it is better to explicitly define the range you want to loop through, see: https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba – Luuklag May 11 '18 at 10:20
  • 1
    Also you don't see any errors in your code, because you explicitly turned them off. Remove your `On Error Resume Next` to see the errors – Luuklag May 11 '18 at 10:23
  • Thanks! I've managed to get them working by opening all the links, but the background colour doesn't change. Looks like it's to do with `If Err.Number <> 0 Then` I've updated my code to reflect – Badja May 11 '18 at 10:33
  • You need to change the color inside the for loop – Luuklag May 11 '18 at 10:50
  • 1
    @pnuts, and its gone.... – Luuklag May 11 '18 at 11:01

0 Answers0