Re: How to initialize an array in VBA of named shapes on a slide?
- From: "Austin Myers" <austinm@xxxxxxx>
- Date: Mon, 20 Feb 2006 09:08:12 -0600
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
================================================
.
- Follow-Ups:
- Re: How to initialize an array in VBA of named shapes on a slide?
- From: Steve Rindsberg
- Re: How to initialize an array in VBA of named shapes on a slide?
- References:
- Re: How to initialize an array in VBA of named shapes on a slide?
- From: Steve Rindsberg
- Re: How to initialize an array in VBA of named shapes on a slide?
- Prev by Date: Re: movies work in mplay32.exe but cause PPT 2003 to freeze when I
- Next by Date: Re: powerpoint for business
- Previous by thread: Re: How to initialize an array in VBA of named shapes on a slide?
- Next by thread: Re: How to initialize an array in VBA of named shapes on a slide?
- Index(es):
Relevant Pages
|