A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Powerpoint, Publisher and Visio » Powerpoint
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Create array based on shape name or tag



 
 
Thread Tools Display Modes
  #1  
Old March 21st, 2007, 12:43 AM posted to microsoft.public.powerpoint
lisa
external usenet poster
 
Posts: 1,001
Default Create array based on shape name or tag

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!
  #2  
Old March 21st, 2007, 03:32 PM posted to microsoft.public.powerpoint
David M. Marcovitz
external usenet poster
 
Posts: 1,267
Default Create array based on shape name or tag

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==?= wrote in
:

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!


  #3  
Old March 21st, 2007, 04:14 PM posted to microsoft.public.powerpoint
lisa
external usenet poster
 
Posts: 1,001
Default Create array based on shape name or tag

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==?= wrote in
:

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!



  #4  
Old March 21st, 2007, 04:27 PM posted to microsoft.public.powerpoint
David M. Marcovitz
external usenet poster
 
Posts: 1,267
Default Create array based on shape name or tag

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==?= wrote in
:

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==?= wrote in
:

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!





  #5  
Old March 21st, 2007, 05:07 PM posted to microsoft.public.powerpoint
lisa
external usenet poster
 
Posts: 1,001
Default Create array based on shape name or tag

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==?= wrote in
:

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==?= wrote in
:

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!






  #6  
Old March 21st, 2007, 06:35 PM posted to microsoft.public.powerpoint
Steve Rindsberg
external usenet poster
 
Posts: 9,366
Default Create array based on shape name or tag


Something like this should do it:

Sub ArrayngeMe()

Dim oSh As Shape
Dim oSl As Slide
Dim rayShapes() As String

ReDim rayShapes(1 To 1) As String

' and for example purposes:
Set oSl = ActivePresentation.Slides(1)

For Each oSh In oSl.Shapes
If oSh.Type = msoAutoShape Then
rayShapes(UBound(rayShapes)) = oSh.Name
ReDim Preserve rayShapes(1 To UBound(rayShapes) + 1) As String
End If
Next

Set oSh = oSl.Shapes.Range(rayShapes).Group

With oSh
' do whatever
oSh.Name = "Bubba"
End With

End Sub

The extra monkey motion with the array is necessary because some versions of PPT
throw errors if you Ubound(ArrayWithNoElements). So instead we ensure that the
array's got one element to start then add more as needed. That leaves us with
one empty element at the end, but the .Range method seems to ignore it. So we
can too.


In article , Lisa wrote:
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!


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


  #7  
Old March 21st, 2007, 06:43 PM posted to microsoft.public.powerpoint
lisa
external usenet poster
 
Posts: 1,001
Default Create array based on shape name or tag

Yeehaw, Yippee, and THANK YOU.
That's exactly what I needed. The example below applies your code to the
test/example I gave earlier. And it works perfectly.
Can't tell you how much I appreciate your help!!!
(And after a nap, I'll see if I can understand how/why your code works and
none of my attempts did... Part, but not all, of my problems were due to
missing the "extra monkey motion" with the array ;-)

UPDATED EXAMPLE
Option Explicit
Dim myShapes As Shapes
Dim myShape As Shape
Dim rayShapes() As String

Sub ThisOlTest2()
'Group and fill shapes named "Ol*" and fill shapes named "Ico*"

Set myShapes = ActivePresentation.Slides("TestArea").Shapes

' Group and apply red fill to all shapes with names beginning with "Ol"
ReDim rayShapes(1 To 1) As String
For Each myShape In myShapes
If myShape.Name Like "Ol*" Then
rayShapes(UBound(rayShapes)) = myShape.Name
ReDim Preserve rayShapes(1 To UBound(rayShapes) + 1) As String
End If
Next
With myShapes.Range(rayShapes).Group
.Name = "ThankYouSteve"
With .Fill
.Visible = msoTrue
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0#
End With
End With
' Apply green fill to all shapes with with names beginning with "Ico" _
(don't group the shapes; just apply fill)
ReDim rayShapes(1 To 1) As String
For Each myShape In myShapes
If myShape.Name Like "Ico*" Then
rayShapes(UBound(rayShapes)) = myShape.Name
ReDim Preserve rayShapes(1 To UBound(rayShapes) + 1) As String
End If
Next
myShapes.Range(rayShapes).Fill.ForeColor.RGB = RGB(0, 255, 0)

End Sub
  #8  
Old March 22nd, 2007, 04:39 AM posted to microsoft.public.powerpoint
Steve Rindsberg
external usenet poster
 
Posts: 9,366
Default Create array based on shape name or tag

In article , Lisa wrote:
Yeehaw, Yippee, and THANK YOU.


g You're welcome. It's easy enough once you've seen it done but a tricky
little thing to get working the first time. The examples in the help files
don't help much, do they?

That's exactly what I needed. The example below applies your code to the
test/example I gave earlier. And it works perfectly.
Can't tell you how much I appreciate your help!!!
(And after a nap, I'll see if I can understand how/why your code works and
none of my attempts did... Part, but not all, of my problems were due to
missing the "extra monkey motion" with the array ;-)

UPDATED EXAMPLE
Option Explicit
Dim myShapes As Shapes
Dim myShape As Shape
Dim rayShapes() As String

Sub ThisOlTest2()
'Group and fill shapes named "Ol*" and fill shapes named "Ico*"

Set myShapes = ActivePresentation.Slides("TestArea").Shapes

' Group and apply red fill to all shapes with names beginning with "Ol"
ReDim rayShapes(1 To 1) As String
For Each myShape In myShapes
If myShape.Name Like "Ol*" Then
rayShapes(UBound(rayShapes)) = myShape.Name
ReDim Preserve rayShapes(1 To UBound(rayShapes) + 1) As String
End If
Next
With myShapes.Range(rayShapes).Group
.Name = "ThankYouSteve"
With .Fill
.Visible = msoTrue
.Solid
.ForeColor.RGB = RGB(255, 0, 0)
.Transparency = 0#
End With
End With
' Apply green fill to all shapes with with names beginning with "Ico" _
(don't group the shapes; just apply fill)
ReDim rayShapes(1 To 1) As String
For Each myShape In myShapes
If myShape.Name Like "Ico*" Then
rayShapes(UBound(rayShapes)) = myShape.Name
ReDim Preserve rayShapes(1 To UBound(rayShapes) + 1) As String
End If
Next
myShapes.Range(rayShapes).Fill.ForeColor.RGB = RGB(0, 255, 0)

End Sub


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


  #9  
Old March 22nd, 2007, 04:25 PM posted to microsoft.public.powerpoint
lisa
external usenet poster
 
Posts: 1,001
Default Create array based on shape name or tag

Agree completely re. the Help files on arrays. Heck, I have trouble with the
Help files in general -- though I have to admit: the more I learn about VBA
the better able I am to glean something useful from VBA Help... Don't think
I'd have ever gotten this array thing down without your help, though.

"Steve Rindsberg" wrote:

In article , Lisa wrote:
Yeehaw, Yippee, and THANK YOU.


g You're welcome. It's easy enough once you've seen it done but a tricky
little thing to get working the first time. The examples in the help files
don't help much, do they?

That's exactly what I needed. The example below applies your code to the
test/example I gave earlier. And it works perfectly...

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:04 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.