Re: How to initialize an array in VBA of named shapes on a slide?

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



Well, this is the very reason I have you guys as my saftey net. <g>


Austin Myers
MS PowerPoint MVP Team

PowerPoint Video and PowerPoint Sound Solutions www.pfcmedia.com




"Steve Rindsberg" <abuse@xxxxxxxxxxxxx> wrote in message news:VA.000021cc.b38eff96@xxxxxxxxxxxxxxxx
In article <E1FF3B48-54D2-4DA6-984E-EC81CA503721@xxxxxxxxxxxxx>, Redhorse wrote:
I am trying to create an array of shapes (while presentation is running)
which have been given specific names (MyShape0, MyShape1, MyShape2...) on a
named slide ("MySlide").

I have tried something like the following but I keep getting runtime errors:

'Global array variable:
Dim MyShapeArray(0 to 11) as Shape

'From within a subroutine in the same module:
With ActivePresentation.Slides("MySlide")
MyShapeArray(0) = .Shapes("MyShape0")
MyShapeArray(1) = .Shapes("MyShape1")
MyShapeArray(2) = .Shapes("MyShape2")
MyShapeArray(3) = .Shapes("MyShape3")
MyShapeArray(4) = .Shapes("MyShape4")
MyShapeArray(5) = .Shapes("MyShape5")
MyShapeArray(6) = .Shapes("MyShape6")
MyShapeArray(7) = .Shapes("MyShape7")
MyShapeArray(8) = .Shapes("MyShape8")
MyShapeArray(9) = .Shapes("MyShape9")
MyShapeArray(10) = .Shapes("MyShapeA")
MyShapeArray(11) = .Shapes("MyShapeB")
End With

For i = 0 To 11
MyShapeArray(i).TextFrame.TextRange.Text = "00"
Next i

The code above gives me an error stating that an object or with variable has
not been set with the "MyShapeArray(0) = .Shapes("MyShape0")" line
highlighted.

Any idea what I'm doing wrong? I have also tried this without using a With
block, by spelling out the full reference to the shape on each line, but that
generates the same error.

Austin must have been taking the Brian Reilly Flying Short Course on Arrays.
Luckily, he slept through most of the classes, so his mind isn't totally
poisoned.

There's no problem with declaring an array of shapes.

If you've got multiple presentations open, be sure the right one is active, of
course.

And you're certain that the slide's name is MySlide?

What if you type this into the immediate window:

? ActivePresentation.Slides("MySlide").Slides.Count

If that gives you an error, there's some kind of problem referencing MySlide.

======================================================================

Oh, and you could simplify the code/maintenance a bit by doing:

Dim x as Long
With ActivePresentation.Slides("MySlide")
For x = Lbound(MyShapeArray) to Ubound(MyShapeArray) - 1
MyShapeArray(x) = .Shapes("MyShape" & cstr(x))
Next
End With

You'd have to name the last two shapes 10 and 11 instead of A and B of course,
but you could add more shapes w/o having to muck with the code beyond re-dimming
the array.

-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================



.



Relevant Pages

  • Re: Create array based on shape name or tag
    ... I've never used it in PowerPoint, ... I'm not sure if you will have to Dim the array to the right size. ... I have sixteen shapes on a slide named "TestArea." ... Set myShapes = ActivePresentation.Slides.Shapes ...
    (microsoft.public.powerpoint)
  • Re: Create array based on shape name or tag
    ... but I don't think that PowerPoint can do the Like thing ... · Check all the shapes on a given slide to determine if they meet ... certain criteria (shape's name contains a specific string, ... · Use the array to group the shapes or to apply properties (fill, ...
    (microsoft.public.powerpoint)
  • Re: Text alignment problems in shapes and text boxes
    ... If this occurs only in files generated from the template I'm tempted to ... "shadow" button is off). ... isn't usually an issue because I avoid using PowerPoint for drawing and labels ... and I wanted to use the PowerPoint shapes to maximize ...
    (microsoft.public.mac.office.powerpoint)
  • RE: Determining the ZOrderPosition. What shape is what?
    ... the VBA editor and you will be able to name your shapes. ... Director of Graduate Programs in Educational Technology ... Author of _Powerful PowerPoint for Educators_ ... Case "Rounded Rectangle 3" ...
    (microsoft.public.powerpoint)
  • Re: Create array based on shape name or tag
    ... Thanks again, David... ... Grouping the shapes in Normal view isn't an option ... My big hurdle is adding the shapes to the array programatically, ... Dim myShapes As Shapes ...
    (microsoft.public.powerpoint)