![]() |
Programmatically add shapes to a selection
I have a worksheet with various shapes already on it. I add new shapes.
I want to collect the new shapes only and group them. How do I build a selection consisting of the newly created shapes. The number of added shapes is dynamic so I don't know of any way to use Array(...) with Range and the shape indexes. TIA *** Sent via Developersdex http://www.developersdex.com *** |
Programmatically add shapes to a selection
This adds a variable number of rectangles and selects them:
Sub Macro2() ActiveCell.Select num = Int(Rnd() * 5 + 1) Debug.Print num For i = 1 To num l = Rnd() * ActiveWindow.VisibleRange.Width t = Rnd() * ActiveWindow.VisibleRange.Height Debug.Print t, l ActiveSheet.Shapes.AddShape(msoShapeRectangle, l, t, _ 55.5, 18#).Select False Next End Sub The false argument to select says to add to the currently selected shape(s) -- Regards, Tom Ogilvy "Edward Ulle" wrote in message ... I have a worksheet with various shapes already on it. I add new shapes. I want to collect the new shapes only and group them. How do I build a selection consisting of the newly created shapes. The number of added shapes is dynamic so I don't know of any way to use Array(...) with Range and the shape indexes. TIA *** Sent via Developersdex http://www.developersdex.com *** |
Programmatically add shapes to a selection
Tom,
Thanks. The select method is so far down the chain I couldn't find it. By the way do you ever sleep? Ed *** Sent via Developersdex http://www.developersdex.com *** |
Programmatically add shapes to a selection
Edward,
I recently had a similar challenge and this is how I was able to do it... When I created the new shapes, I added some identifying characters to each shape name. (.Name = "XXX" & .Name). Then when I wanted to find the shapes, I iterated through all of the shapes in the worksheet. When I found one whose name began with the string that I added, I added that name to an array of variants. It must be an array of Variants, not strings. Then I created a ShapeRange set containing the names that I wanted (Set SR = ActiveSheet.Shapes.Range(ShapeNames()), where ShapeNames() is the array of names) Then you could execute SR.Select to get where you want. In my case I created a Shape Group. I was able to get it to work in this manner. Hope that this helps. Dan Fisher "Edward Ulle" wrote in message ... I have a worksheet with various shapes already on it. I add new shapes. I want to collect the new shapes only and group them. How do I build a selection consisting of the newly created shapes. The number of added shapes is dynamic so I don't know of any way to use Array(...) with Range and the shape indexes. TIA *** Sent via Developersdex http://www.developersdex.com *** |
All times are GMT +1. The time now is 12:32 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com