Pasting shapes with VBA

J

Jessie

In my program, I paste a shape on the background page onto every other page
if the user so desires. Each shape on each page exists independently(i.e.
has its own data). I need to be able to delete that shape from every page
as well. To do so, I need to be able to reference each pasted shape. I lose
the reference when i paste the shape. I need that pasted shape to have the
same name as the shape it was copied from, but when I paste it, it has a
different name. I need to change the name.

Does anyone know how I can keep the reference of the pasted shape so I can
change its name?

Thanks
 
P

Paul Herber

In my program, I paste a shape on the background page onto every other page
if the user so desires. Each shape on each page exists independently(i.e.
has its own data). I need to be able to delete that shape from every page
as well. To do so, I need to be able to reference each pasted shape. I lose
the reference when i paste the shape. I need that pasted shape to have the
same name as the shape it was copied from, but when I paste it, it has a
different name. I need to change the name.

Does anyone know how I can keep the reference of the pasted shape so I can
change its name?

When the shape has been dropped the new shape will be the last in the
page.shapes[] collection. The index to get this shape is
page.shapes.count
You may need to set both the shape.name and shape.nameU with an
exception handler around the renaming in case the shape renaming
fails.
 
J

Jessie

Paul Herber said:
In my program, I paste a shape on the background page onto every other page
if the user so desires. Each shape on each page exists independently(i.e.
has its own data). I need to be able to delete that shape from every page
as well. To do so, I need to be able to reference each pasted shape. I lose
the reference when i paste the shape. I need that pasted shape to have the
same name as the shape it was copied from, but when I paste it, it has a
different name. I need to change the name.

Does anyone know how I can keep the reference of the pasted shape so I can
change its name?

When the shape has been dropped the new shape will be the last in the
page.shapes[] collection. The index to get this shape is
page.shapes.count
You may need to set both the shape.name and shape.nameU with an
exception handler around the renaming in case the shape renaming
fails.


Thanks.

I've never used Exception handlers with Visual Basic before. I can't seem
to find information on exception handlers for renaming shapes... how do I go
about this?
 
P

Paul Herber

I've never used Exception handlers with Visual Basic before. I can't seem
to find information on exception handlers for renaming shapes... how do I go
about this?

Look in the VB help for On Error
 
J

Jessie

Paul Herber said:
Look in the VB help for On Error

So I don't actually get an error when i try to rename the shape, it just
doesn't change the name.

pastedShape.Name = "Sheet.142" doesn't change the name. However if I say

pastedShape.Name = "Hello", it DOES change the name.

Sheet.142 is the name of the shape I copied, and now I want the pasted shape
to have the same name. Weird that it won't change the shape's name to
Sheet.142 but will change the name to a string like Hello.

Anyone know why this is? What am I missing here?
 
P

Paul Herber

So I don't actually get an error when i try to rename the shape, it just
doesn't change the name.

pastedShape.Name = "Sheet.142" doesn't change the name. However if I say

pastedShape.Name = "Hello", it DOES change the name.

Sheet.142 is the name of the shape I copied, and now I want the pasted shape
to have the same name. Weird that it won't change the shape's name to
Sheet.142 but will change the name to a string like Hello.

Anyone know why this is? What am I missing here?

Every shape on a page must have a different name, if Sheet.142 already
exists then you cannot rename a shape to have this name, whereas
"Hello" is a quite valid shape name.
The point of the error handler is to recognise that the renaming has
failed and that you have to do something about it, like choose another
name, but the way you choose a name will depend upon what you are
trying to do.
 
J

Jessie

Paul Herber said:
Every shape on a page must have a different name, if Sheet.142 already
exists then you cannot rename a shape to have this name, whereas
"Hello" is a quite valid shape name.
The point of the error handler is to recognise that the renaming has
failed and that you have to do something about it, like choose another
name, but the way you choose a name will depend upon what you are
trying to do.


Sheet.142 is from the background page, and is not on the same page as the
shape I'm renaming. They are in the same document, but on different pages.
Does you response above still apply?
 
P

Paul Herber

Sheet.142 is from the background page, and is not on the same page as the
shape I'm renaming. They are in the same document, but on different pages.
Does you response above still apply?

Possibly, each shape has a local name and a universal name, there may
still be a conflict.
Please try out my utilities which can list all the shapes within a
page/document displaying their internal names. Details below.
 

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