Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Selection order problem with code for shapes connection

I am trying to write a little macro that will connect the 2 selected
autoshapes flow chart boxes. My problem is if I put 5 boxes on the
worksheet and have them ordered 5-4-3-2-1. If I select #5 and them #4
it wants to connect #4 to #5. My code can not get the name of the first
selected box(#5) as item(1).name. You can see all the ways I tried to
get A & B to give me A=5 and B=4 in the scenario I described. If anyone
can help me on my selection order problem I would appreciate it.
Thanks
Scott


Sub shapeconnect()
A = Selection.Item(1).Name
B = Selection.Item(2).Name

A = Selection.ShapeRange.Item(1).Name
B = Selection.ShapeRange.Item(2).Name

A = Selection.ShapeRange(1).Name
B = Selection.ShapeRange(2).Name

A = Selection(1).ShapeRange.Item(1).Name
B = Selection(2).ShapeRange.Item(1).Name

ActiveSheet.Shapes.AddConnector(msoConnectorStraig ht, 129.75,
130.5, 1.5, 16.5).Select
Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
Selection.ShapeRange.Flip msoFlipHorizontal
Selection.ShapeRange.Flip msoFlipVertical
Selection.ShapeRange.ConnectorFormat.BeginConnect
ActiveSheet.Shapes(A), 3
Selection.ShapeRange.ConnectorFormat.EndConnect
ActiveSheet.Shapes(B), 1
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default Selection order problem with code for shapes connection

Hi,

the following code works in excel 2000.

'accessing object(e.g. "selobj(i).Name") seems to reset selection order.

Function SelectedObjects() As Variant
Dim a() As Object, obj As Object
Dim i As Long
If TypeName(Selection) = "DrawingObjects" Then
ReDim a(1 To Selection.Count)
For Each obj In Selection
i = i + 1
Set a(i) = obj
Next
SelectedObjects = a
End If
End Function

Sub Test()
Dim selobj As Variant
Dim i As Long
selobj = SelectedObjects()
If IsArray(selobj) Then
For i = 1 To UBound(selobj)
Debug.Print selobj(i).Name
Next
End If
End Sub

--
HTH,

okaizawa

wrote:
I am trying to write a little macro that will connect the 2 selected
autoshapes flow chart boxes. My problem is if I put 5 boxes on the
worksheet and have them ordered 5-4-3-2-1. If I select #5 and them #4
it wants to connect #4 to #5. My code can not get the name of the first
selected box(#5) as item(1).name. You can see all the ways I tried to
get A & B to give me A=5 and B=4 in the scenario I described. If anyone
can help me on my selection order problem I would appreciate it.
Thanks
Scott


Sub shapeconnect()
A = Selection.Item(1).Name
B = Selection.Item(2).Name

A = Selection.ShapeRange.Item(1).Name
B = Selection.ShapeRange.Item(2).Name

A = Selection.ShapeRange(1).Name
B = Selection.ShapeRange(2).Name

A = Selection(1).ShapeRange.Item(1).Name
B = Selection(2).ShapeRange.Item(1).Name

ActiveSheet.Shapes.AddConnector(msoConnectorStraig ht, 129.75,
130.5, 1.5, 16.5).Select
Selection.ShapeRange.Line.EndArrowheadStyle = msoArrowheadTriangle
Selection.ShapeRange.Flip msoFlipHorizontal
Selection.ShapeRange.Flip msoFlipVertical
Selection.ShapeRange.ConnectorFormat.BeginConnect
ActiveSheet.Shapes(A), 3
Selection.ShapeRange.ConnectorFormat.EndConnect
ActiveSheet.Shapes(B), 1
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Selection order problem with code for shapes connection

Thanks for the sanity check. I could not figure out what was happening.
It is kind of odd that .name changes the selection order.
I tweaked the code you sent me and it works perfectly for my
application. I can select 10 autoshapes and it puts arrows between each
of them in the order that I selected them.
Thanks a ton!!!
Scott

Here is the code I ended up with for those who are interested:

Function SelectedObjects() As Variant
Dim a() As Object, obj As Object
Dim i As Long
If TypeName(Selection) = "DrawingObjects" Then
ReDim a(1 To Selection.Count)
For Each obj In Selection
i = i + 1
Set a(i) = obj
Next
SelectedObjects = a
End If
End Function


Sub Test()
Dim selobj As Variant
Dim i As Long
'accessing object(e.g. "selobj(i).Name") seems to reset selection
order.
selobj = SelectedObjects()
If IsArray(selobj) Then
For i = 1 To UBound(selobj) - 1
Debug.Print selobj(i).Name
ActiveSheet.Shapes.AddConnector(msoConnectorStraig ht,
129.75, 130.5, 1.5, 16.5).Select
Selection.ShapeRange.Line.EndArrowheadStyle =
msoArrowheadTriangle
Selection.ShapeRange.Flip msoFlipHorizontal
Selection.ShapeRange.Flip msoFlipVertical
Selection.ShapeRange.ConnectorFormat.BeginConnect
ActiveSheet.Shapes(selobj(i).Name), 3
i = i + 1
Selection.ShapeRange.ConnectorFormat.EndConnect
ActiveSheet.Shapes(selobj(i).Name), 1
i = i - 1
Next
End If
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmatically add shapes to a selection Edward Ulle Excel Programming 3 August 8th 05 12:17 AM
Programmatically add shapes to a selection Edward Ulle Excel Programming 0 June 1st 05 08:29 PM
Tab Order Code Problem Ryan Excel Programming 3 April 19th 04 05:01 PM
Date Range Selection the ODBC connection to database Steve Mildner Excel Programming 1 January 13th 04 11:12 AM
Disable selection of shapes Mike Excel Programming 3 December 17th 03 01:43 PM


All times are GMT +1. The time now is 11:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"