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,960
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,078,541
Messages
5,341,061
Members
399,414
Latest member
EMW2159

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top