Trying to reverse arrow head shape in diagram

therealjag

New Member
Joined
Nov 13, 2019
Messages
2
Hi there,

I have a diagram where I've created over a 100 arrows. However I am trying to reverse the arrow heads from flat to triangle and vice versa but my code doesn't seem to be working. The code doesn't recognise the line/connector type so that I can reverse it. any ideas?

Code:
Sub reversearrows()

Dm sh as Shape

For each sh in ActiveSheet.shapes
 if sh.type = msoLine Then
  if sh.line.beginarrowheadstyle = msoarrowheadnone Then
     sh.line.beginarrowheadstyle = msoarrowheadtriangle
     sh.line.endarrowheadstyle = msoarrowheadnone
  elseIf sh.line.beginarrowheadstyle = msoarrowheadTriangle Then
     sh.line.beginarrowheadstyle = msoarrowheadNone
     sh.line.endarrowheadstyle = msoarrowheadTriangle
  end if
end if
Next

End Sub
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
5,943
Welcome to MrExcel. I think you just need to select each shape:
Code:
Sub reversearrows()

    Dim sh As Shape
    
    For Each sh In ActiveSheet.Shapes
        If sh.Type = msoLine Then
            sh.Select
            If sh.Line.BeginArrowheadStyle = msoArrowheadNone Then
                sh.Line.BeginArrowheadStyle = msoArrowheadTriangle
                sh.Line.EndArrowheadStyle = msoArrowheadNone
            ElseIf sh.Line.BeginArrowheadStyle = msoArrowheadTriangle Then
                sh.Line.BeginArrowheadStyle = msoArrowheadNone
                sh.Line.EndArrowheadStyle = msoArrowheadTriangle
            End If
        End If
    Next
    ActiveCell.Select
    
End Sub
 

therealjag

New Member
Joined
Nov 13, 2019
Messages
2
Hi there,

I managed to figure it out. For some odd reason "sh.type" wasn't recognising the line type property, so I changed it to sh.AutoShapeType which did the trick. Another odd one was that it was returning "-2" for the arrow shape which equates to "msoShapeMixed", again not sure why that is so if anyone has an answer that would be great.

Cheers,

Working code below:

Code:
Sub reversearrows()

    Dim sh As Shape
    
    For Each sh In ActiveSheet.Shapes
     sh.Select
        If sh.AutoShapeType = -2 Then 'msoShapeMixed
            If sh.Line.BeginArrowheadStyle = msoArrowheadNone Then
                sh.Line.BeginArrowheadStyle = msoArrowheadTriangle
                sh.Line.EndArrowheadStyle = msoArrowheadNone
            ElseIf sh.Line.BeginArrowheadStyle = msoArrowheadTriangle Then
                sh.Line.BeginArrowheadStyle = msoArrowheadNone
                sh.Line.EndArrowheadStyle = msoArrowheadTriangle
            End If
        End If
    Next
    ActiveCell.Select
    
End Sub
 

Forum statistics

Threads
1,077,687
Messages
5,335,662
Members
399,033
Latest member
thefinu

Some videos you may like

This Week's Hot Topics

Top