2

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" 
Mayukh Bhattacharya
  • 12,541
  • 5
  • 21
  • 32
Eagle97
  • 21
  • 3
  • see https://stackoverflow.com/questions/50911808/check-if-hyperlink-exists-in-a-shape. Instead of `MsgBox "in shape: " & h.Shape.Name` in top answer use: `h.Shape.Fill.ForeColor.RGB = vbBlue`. – ouroboros1 May 02 '22 at 14:50

1 Answers1

2

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
VBasic2008
  • 44,888
  • 5
  • 17
  • 28