Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default 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 ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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 ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default 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 ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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 ***



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
excel document with shapes on it but the shapes do not print [email protected] Excel Worksheet Functions 2 October 22nd 09 06:17 PM
Naming Auto Shapes and Creating new Shapes AL2000 Excel Discussion (Misc queries) 3 September 10th 07 04:12 AM
When drawing shapes in excel the shapes keep disappearing Tape Excel Discussion (Misc queries) 1 October 6th 06 04:23 PM
Programmatically add shapes to a selection Edward Ulle Excel Programming 0 June 1st 05 08:29 PM
Disable selection of shapes Mike Excel Programming 3 December 17th 03 01:43 PM


All times are GMT +1. The time now is 11:26 PM.

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"