Re: Create array based on shape name or tag
- From: Lisa <Lisa@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 21 Mar 2007 10:07:08 -0700
Thanks again, David... Grouping the shapes in Normal view isn't an option
under the circumstances (a macro to build a slide with specific elements in
case somebody deletes or tinkers with the slide -- after the file is outside
my hot little hands ;-)
I'm brand new to arrays (and pretty green with VBA in general), but via Help
files, am able to group shapes using an array. For example, see below.
My big hurdle is adding the shapes to the array programatically, rather than
by typing out the names. Have tried a couple dozen approaches -- all of which
will list the shape names in message boxes, or whatever, in a way that looks
like it might work, -- and all of which give me a runtime error when I try to
use the list to define the content of the array. SIGH
Anyhoooo, I appreciate your input and tips re. arrays in general.
EXAMPLE GROUPING ITEMS IN AN ARRAY
The following sub is similar to previous example (applies red fill to three
named shapes) -- after grouping the shapes.
Sub AnotherTest()
Dim myShapes As Shapes
Dim myShape As Shape
Dim TestArray As Variant
Set myShapes = ActivePresentation.Slides("TestArea").Shapes
TestArray = Array("Olive", "Ollaly", "OlBoy")
With myShapes.Range(TestArray).Group
.Name = "Testing"
With .Fill
.Visible = msoTrue
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0#
End With
End With
End Sub
"David M. Marcovitz" wrote:
Sorry, I must have misread your post. I'm glad that Like works for you..
I've never used it in PowerPoint, so I learned something new.
Unfortunately, I've never done quite what your doing (grouping from an
array) so I'm not sure how it will work, but you seem to know that part.
I'm not sure if you will have to Dim the array to the right size. If you
know how many items meet your criteria, you could Dim it in advance. If
you don't, you could run through your loop twice. The first time, you
could count how many items. Then, use Redim to set the size of your
array. Then loop through again and fill your array. This is assuming that
you actually need to know the size of the array, and I'm not sure you do.
If you are working in Normal View, you could select each object and group
the selection instead of trying to build an array.
Good luck. I wish I had a few minutes to play with this and give you more
specific advice, but I don't right now.
--David
--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
=?Utf-8?B?TGlzYQ==?= <Lisa@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
news:71FD50BF-B0F9-49F6-95FB-2BD8ED6EB977@xxxxxxxxxxxxx:
Thanks for the response, David...
Fortunately, the Like thing does seem to work in PPT... For example
see below.
My problem is figuring out how to put the items that meet the Like
criterion into an array so I can group them... Or group them somehow
(I'm not married to the "array" notion, it's just my best guess as to
how I could "collect" a bunch of stuff that meets the criteria so I
can use .group).
EXAMPLE: I have sixteen shapes on a slide named "TestArea." One is
named "Olive," another "Olboy," and a third named "Ollaly." The other
shapes have names that don't begin with "Ol." This macro applies a red
fill to the three "Ol*" and leaves the others alone.)
Option Explicit
Dim myShapes As Shapes
Dim myShape As Shape
Sub ThisOlTest()
Set myShapes = ActivePresentation.Slides("TestArea").Shapes
For Each myShape In myShapes
If myShape.Name Like "Ol*" Then
With myShape.Fill
.Visible = msoTrue
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0#
End With
End If
Next
End Sub
"David M. Marcovitz" wrote:
I could be wrong, but I don't think that PowerPoint can do the Like
thing that you want. You could write more complex If statements,
using such string manipulation functions as Left.
--David
--
David M. Marcovitz
Microsoft PowerPoint MVP
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.PowerfulPowerPoint.com/
=?Utf-8?B?TGlzYQ==?= <Lisa@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
news:45A49BAA-ECB1-4A97-A603-734B70825067@xxxxxxxxxxxxx:
Essentially, I'm trying to:
· Check all the shapes on a given slide to determine if they
meet certain criteria (shape's name contains a specific string, or
shape's tag has a specific value)
· If a shape meets the criteria, add it to an array
· Use the array to group the shapes or to apply properties
(fill, line, etc) to the shapes in the array
For example, a condensed version of my current code looks something
like this:
myArray = Array("Icon_Hat", "Icon_Tree", "Icon_Star")
With myShapes.Range(myArray).Group
.Name = "myTestEffort"
With .Fill
.Solid
.ForeColor.RGB = RGB(255, 153, 51)
End With
.Line.Visible = msoFalse
End With
Instead of defining the array by listing each shape by name, I'd
like to be able to say something like
If myShape.Name Like "Icon_*" Then ... (put it in myArray)
OR
If myShape.Tags("ImgStyle") = "Icon" Then ... (put it in
myArray)
Unfortunately, I keep getting stuck at the "put it in myArray"
part.
If someone can tell me how to do this -- or refer me to appropriate
documentation, I'd really appreciate it.
Thanks in advance!
- References:
- Re: Create array based on shape name or tag
- From: David M. Marcovitz
- Re: Create array based on shape name or tag
- From: Lisa
- Re: Create array based on shape name or tag
- From: David M. Marcovitz
- Re: Create array based on shape name or tag
- Prev by Date: Re: Where are the guide lines in PowerPoint 2007?
- Next by Date: Pls. help with odd issue
- Previous by thread: Re: Create array based on shape name or tag
- Next by thread: Re: Create array based on shape name or tag
- Index(es):
Relevant Pages
|