Looping through shape names?

R

robdonn

Is there any way to loop through shape names using variables?

The following code I want to use doesn't work

For X = 1 to 6
For Y = 100 to 500 step 100
shape_name = Str(X) & "-" & Str(Y)
ActivePresentation.Slides(4).Shapes(shape_name).Visible = False
Next Y
Next X

The code it replaces is repetitive but does work

ActivePresentation.Slides(4).Shapes("1-100").Visible = False
ActivePresentation.Slides(4).Shapes("1-200").Visible = False
ActivePresentation.Slides(4).Shapes("1-300").Visible = False
etc, etc to
ActivePresentation.Slides(4).Shapes("6-400").Visible = False
ActivePresentation.Slides(4).Shapes("6-500").Visible = False

Can anyone help me?
 
G

Guest

Robdonn

Str(X) & "-" & Str(Y
and
Trim(Str(X)) & "-" & trim(Str(Y)

will give distinctively different results. Str appends a space prior to the returned string for positive values.
10-100 is different from 10- 10

Regard
Shyam Pilla

http://www.mvps.org/sk


----- robdonn wrote: ----

Is there any way to loop through shape names using variables

The following code I want to use doesn't work

For X = 1 to
For Y = 100 to 500 step 10
shape_name = Str(X) & "-" & Str(Y)
ActivePresentation.Slides(4).Shapes(shape_name).Visible = Fals
Next
Next

The code it replaces is repetitive but does work

ActivePresentation.Slides(4).Shapes("1-100").Visible = Fals
ActivePresentation.Slides(4).Shapes("1-200").Visible = Fals
ActivePresentation.Slides(4).Shapes("1-300").Visible = Fals
etc, etc t
ActivePresentation.Slides(4).Shapes("6-400").Visible = Fals
ActivePresentation.Slides(4).Shapes("6-500").Visible = Fals

Can anyone help me
 
S

Steve Rindsberg

For X = 1 to 6
For Y = 100 to 500 step 100
shape_name = Str(X) & "-" & Str(Y)
ActivePresentation.Slides(4).Shapes(shape_name).Visible = False
Next Y
Next X

Use Cstr instead of Str:

shape_name = Cstr(X) & "-" & Cstr(Y)

Str reserves a place for a +/- sign and gives you a space if the value is
positive, so it's giving you values like " 100- 1" instead of "100-1"

Easy to catch if you do:
Debug.Print shape_name

after assigning shape_name a value
 
B

B

There are several versions of presentations that approximate Jeopardy. Is
this a learning tool for you, or something would rather not re-invent?

B
===============
Please spend a few minutes checking vestprog2@
out www.pptfaq.com This link will yahoo.
answer most of our questions, before com
you think to ask them.

Change org to com to defuse anti-spam,
ant-virus, anti-nuisance misdirection.
..
..

Shyam Pillai said:
Robdonn,

Str(X) & "-" & Str(Y)
and
Trim(Str(X)) & "-" & trim(Str(Y))

will give distinctively different results. Str appends a space prior to
the returned string for positive values.
 
R

robdonn

Thanks for all your help. No problems now.

Steve Rindsberg said:
Use Cstr instead of Str:

shape_name = Cstr(X) & "-" & Cstr(Y)

Str reserves a place for a +/- sign and gives you a space if the value is
positive, so it's giving you values like " 100- 1" instead of "100-1"

Easy to catch if you do:
Debug.Print shape_name

after assigning shape_name a value
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top