Functon to change Shape Color If they are Hyperlinked

Viewed 35

I am looking to create a VBA functon to change the color of a shape if there is a hyperlink attached.

Not sure if this helps:

ActiveSheet.Shapes.Hyperlink.Fill.ForeColor.RGB = vbBlue

...

"IF(Shape contains hyperlink)
    Change shape color to blue
Else
    No change" 
1 Answers

Change the Color of Shapes

Sub ChangeShapesColor()

    Dim ws As Worksheet: Set ws = ActiveSheet ' improve!
    
    Application.ScreenUpdating = False
    
    Dim shp As Shape
    Dim hl As Hyperlink
    
    For Each shp In ws.Shapes
        
        On Error Resume Next
            Set hl = shp.Hyperlink
        On Error GoTo 0
        'Debug.Print shp.Name, Not hl Is Nothing
        
        If Not hl Is Nothing Then
            shp.Fill.ForeColor.RGB = vbYellow ' RGB(255, 255, 0)
            Set hl = Nothing
        End If
        
    Next shp
    
    Application.ScreenUpdating = True
    
    MsgBox "Shapes' color changed.", vbInformation
    
End Sub
Related