Can I use VBA to assign Macro to Shape within a Group of Shapes?

M

MikeZz

Hi,
I have a group of shapes pre-built in one workbook that I want to copy to
another, then assign all the individual shapes to execute various macros in
the finished workbook.

I figured out how to do this on individual shapes this way:
ActiveSheet.Shapes("boxAF153").OnAction = "AF_Custom"

The question is if the shapes are copied over as part of a group, and I want
them to remain in a group, how do I refer to an individual shape within a
group?

I've tried the following but all give me "error 438".
The name of the shape Group is "Group 51" and one of the indvidual shapes is
"boxAF153"

ActiveSheet.Shapes.GroupItems("Group 51").Item("boxAF153").OnAction =
"AF_Custom"
ActiveSheet.GroupShapes(1).Items(1).OnAction = "AF_Custom"

Thanks for any help,
MikeZz
 
J

Jim Cone

You have to ungroup the shapes, assign a macro to each individual
shape and then regroup the shapes...
'--
ActiveSheet.Shapes.GroupItems("Group 51").Ungroup
ActiveSheet.Shapes("boxAF153").OnAction = "AF_Custom"
'assign more macros here
ActiveSheet.Shapes.Range("boxAF153").ReGroup
'--
MS didn't make it easy to understand.
--
Jim Cone
Portland, Oregon USA




"MikeZz"
<[email protected]>
wrote in message
Hi,
I have a group of shapes pre-built in one workbook that I want to copy to
another, then assign all the individual shapes to execute various macros in
the finished workbook.

I figured out how to do this on individual shapes this way:
ActiveSheet.Shapes("boxAF153").OnAction = "AF_Custom"

The question is if the shapes are copied over as part of a group, and I want
them to remain in a group, how do I refer to an individual shape within a
group?

I've tried the following but all give me "error 438".
The name of the shape Group is "Group 51" and one of the indvidual shapes is
"boxAF153"

ActiveSheet.Shapes.GroupItems("Group 51").Item("boxAF153").OnAction =
"AF_Custom"
ActiveSheet.GroupShapes(1).Items(1).OnAction = "AF_Custom"

Thanks for any help,
MikeZz
 

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