Problem Drawing Arrows

NewOrderFac33

Well-known Member
Joined
Sep 26, 2011
Messages
1,283
Office Version
  1. 2016
  2. 2010
Platform
  1. Windows
Good afternoon,

The following code, which works on my PC at work (Office 2010/Win 7) won't work on my PC at home (Office 2010/Win XP). The line draws successfully, but if any of the commented out lines are uncommented, they return the error message: "The specified value is out of range".

As I input the code manually, because I can't email code from work, I'm just wondering if anyone can see anything wrong with it. Perhaps I set a reference to something at work that I've forgotten?

Code:
Sub AA_Test()
    Set MyDocument = Worksheets("MailMe")
    With MyDocument.Shapes.AddLine(100, 100, 200, 300).Line
        '.BeginArrowheadLength = msoArrowheadShort
        '.BeginArrowheadStyle = msoArrowheadOval
        '.BeginArrowheadWidth = msoArrowheadNarrow
        '.EndArrowheadLength = msoArrowheadLong
        '.EndArrowheadStyle = msoArrowheadTriangle
        '.EndArrowheadWidth = msoArrowheadWide
    End With
End Sub
[code]

Thanks in advance for your help.

Pete
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Microsoft Office xx Object Library?
 
Upvote 0
Microsoft Office xx Object Library?
No, I already have that one. Not to worry, I'll just take a look on Monday when I'm back in. Funny that I can draw the line, but just not add the embellishments to it.

Have a nice weekend.

Pete
 
Upvote 0
Shg,
I checked my work PC and the references for the workbook are identical to those at home (VBA, MS Excel 14.0 Object Library, MS Office 14.0 Object Library and OLE Automation)
Just as a matter of interest, were YOU able to get my code to run? Here's the full thing:
Code:
Sub DrawLineBetweenSelectedCells()
    With Selection
        If .Count = 2 Then
            If .Areas.Count = 1 Then
                Arrow .Cells(1), .Cells(2)
            Else
                Arrow .Areas(1), .Areas(2)
            End If
        End If
    End With
End Sub


Sub DrawLineBetweenTwoCellAddresses()
    Arrow Range("A1"), Range("A10")
End Sub


Sub Arrow(rnStart As Range, rnEnd As Range)
    With ActiveSheet.Shapes.AddLine(MOC(rnStart), MOC(rnStart, True), MOC(rnEnd), MOC(rnEnd, True)).Line
        .EndArrowheadStyle = msoArrowheadTriangle 'msoArrowheadOpen
        .EndArrowheadLength = msoArrowheadLengthMedium
        .EndArrowheadWidth = msoArrowheadWidthMedium
        .ForeColor.RGB = RGB(255, 0, 0)
        .Weight = 2
        .Visible = msoTrue
    End With
End Sub
 
'Required by the Arrow procedure
Function MOC(R As Range, Optional Y As Boolean) As Long 'if y is false or omitted, the X pos is returned
    If Y Then
        MOC = R.Top + R.Height / 2
    Else
        MOC = R.Left + R.Width / 2
    End If
End Function
Cheers
Pete
 
Upvote 0
FYI I tried this code on a work colleague's PC and it works fine - looks like a reinstall of Office at home is called for!
 
Upvote 0

Forum statistics

Threads
1,225,201
Messages
6,183,535
Members
453,168
Latest member
Luggsy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top