Re: programmatically selecting multiple shapes

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Tom Ogilvy (twogilvy_at_msn.com)
Date: 02/18/05


Date: Fri, 18 Feb 2005 13:00:40 -0500

this worked for me:

Sub AAA()
Dim j As Long, i As Long
Dim varr(0 To 2)
j = 0
For i = 1 To 6 Step 2
varr(j) = i
j = j + 1
Next

ActiveSheet.Shapes.Range(varr). _
        Select
End Sub

Not very dynamic as written, but could be modified.

-- 
Regards,
Tom Ogilvy
"ACW" <ACW.1knsfq@excelforum-nospam.com> wrote in message
news:ACW.1knsfq@excelforum-nospam.com...
>
> Thanks Leith.
>
> This is also where I got stuck. Like you mention below, what
> code/method will select a set of shapes during run time?
>
> I can actually get buy with a hardcoded list of shapes, but I rather
> not for robustness.
>
> Perhaps there's a way to build the list that can be given to the array
> function. I tried that using an array of strings "Array(MyArrayList)",
> but that results in a two dimensional array and the error message "type
> mismatch". So, then I tried simply using a array of strings and then
> "MyArrayList". This resulted in the same error message. The sample code
> below. I also tried making MyArray a Variant with the same result.
>
>
> Dim MyArray(3) As String
>
>
> MyArray(0) = 1
> MyArray(1) = 3
> MyArray(2) = 4
>
> ActiveSheet.Shapes(Array(MyArray)).Select
> ActiveSheet.Shapes(MyArray).Select
>
> Thanks again. I really appreciate you helping me look into this.
>
>
>
> Leith Ross Wrote:
> > Hi Again ACW,
> >
> > This is an addendum to the last post. I figured out what I was doing
> > wrong.
> >
> > You can select the Shapes by Index Number, and without having to select
> > them all first!
> > _________________________________________________________________
> >
> > EXAMPLE - SAY THERE ARE 10 SHAPES ON WORKSHEET \"SHEET1\" AND YOU WANT
> > TO SELECT 3 OF YOUR CHOOSING. THIS IS HOW:
> >
> > Sheets("Sheet1").Shapes.Range(Array(1, 3, 7)).Select
> > _________________________________________________________________
> >
> > The drawback is the Array is integrated into the code segment. In other
> > words, the number of elements is set at design time. Haven't figured out
> > a work around for this yet, if there is one. Now at least, you don't
> > have to use the names to select the shape.
> >
> > Sorry for the inconvenience,
> > Leith Ross
>
>
> -- 
> ACW
> ------------------------------------------------------------------------
> ACW's Profile:
http://www.excelforum.com/member.php?action=getinfo&userid=20033
> View this thread: http://www.excelforum.com/showthread.php?threadid=346145
>


Relevant Pages

  • Re: Updated datestamp doesnt work
    ... Public Sub StoreMyOldVals ... ' store values of current row in array ... Dim dbs As DAO.Database, rst As DAO.Recordset ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)
  • Re: Updated datestamp doesnt work
    ... Public Sub StoreMyOldVals ... ' store values of current row in array ... Dim dbs As DAO.Database, rst As DAO.Recordset ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)
  • Re: Updated datestamp doesnt work
    ... Public Sub StoreMyOldVals ... ' store values of current row in array ... Dim dbs As DAO.Database, rst As DAO.Recordset ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)
  • Re: referencing/sorting arrays
    ... Public Sub SortArrayAscendAs Integer) ... 'Sort an array in ascending order ... Dim Idx01 As Integer ... >> If no data type declaration is made for the argument it becomes a variant. ...
    (microsoft.public.excel.programming)
  • Re: Updated datestamp doesnt work
    ... Public Sub StoreOldVals ... ' store values of current row in array ... Dim n As Integer, intlast As Integer ... Dim var As Variant ...
    (microsoft.public.access.gettingstarted)