Visio.ActiveWindow.Selection.Item(i) gives INVALID SELECTIONIDENTIFIER

J

Jessica.Hromiko

My program is supposed to bring up a window to ask the user which
shapes should exist independently on every page. Initially, shapes
only exist on the background page. If the user checks the checkbox
next to the shape on the form, then I copy that shape from the
background page and paste it to every page before. I need to be able
to keep the same name for that shape on every page (in case the user
wants to delete the shape from every page), but Visio change the name
of the pasted shape when pasted.

I figured I needed to save a reference to the copied shape and change
the name of the pasted shape by doing this:
I pasted the shape, then Set copiedShape =
Visio.ActiveWindow.Selection.Item(i), then I set the copiedShape.Name
to the original name, so that if the user wants to delete the shape on
every page using the form described previously, they can do so.
However, when I use Visio.ActiveWindow.Selection.Item(i), it gives me
"INVALID SELECTION IDENTIFIER". Do you know if there is a better way
to do this, or what my error means?

Thanks,
Jessie Hromiko
 
P

Paul Herber

My program is supposed to bring up a window to ask the user which
shapes should exist independently on every page. Initially, shapes
only exist on the background page. If the user checks the checkbox
next to the shape on the form, then I copy that shape from the
background page and paste it to every page before. I need to be able
to keep the same name for that shape on every page (in case the user
wants to delete the shape from every page), but Visio change the name
of the pasted shape when pasted.

I figured I needed to save a reference to the copied shape and change
the name of the pasted shape by doing this:
I pasted the shape, then Set copiedShape =
Visio.ActiveWindow.Selection.Item(i), then I set the copiedShape.Name
to the original name, so that if the user wants to delete the shape on
every page using the form described previously, they can do so.
However, when I use Visio.ActiveWindow.Selection.Item(i), it gives me
"INVALID SELECTION IDENTIFIER". Do you know if there is a better way
to do this, or what my error means?

I think that what is happening here is that as soon as you paste your
shape into the new page, that page then becomes the active page,
hence, your ActiveWindow now relates to a different page.
How about, as soon as you know the selection keep a record of all the
shapes in a shape collection, or even just a string list containing
all the shape names.
 
J

Jessica.Hromiko

I think that what is happening here is that as soon as you paste your
shape into the new page, that page then becomes the active page,
hence, your ActiveWindow now relates to a different page.
How about, as soon as you know the selection keep a record of all the
shapes in a shape collection, or even just a string list containing
all the shape names.

I see what you mean- I'm still a bit confused though. The purpose of
me using ActiveWindow.selection was to try get the shape I just
pasted. I need a reference to the shape I just pasted so that I can
change its name. Anyone know how I can do this?

Thanks,
Jessie Hromiko
 
P

Paul Herber

I see what you mean- I'm still a bit confused though. The purpose of
me using ActiveWindow.selection was to try get the shape I just
pasted. I need a reference to the shape I just pasted so that I can
change its name. Anyone know how I can do this?

How about, as soon as you know the selection keep a record of all the
shapes in a shape collection, or even just a string list containing
all the shape names.
 
J

Jessica.Hromiko

How about, as soon as you know the selection keep a record of all the
shapes in a shape collection, or even just a string list containing
all the shape names.

I must be misunderstanding you-

"How about, as soon as you know the selection keep a record of all the
shapes in a shape collection, or even just a string list containing
all the shape names. "

do you mean as soon as I know the original selection, as in, the shape
that is wanted on every page? Does the string list contain the names
of the shapes I pasted? Because that's what I'm trying to get- the
name of the shape I pasted. All I want is to be able to paste a
shape, get the name of that pasted shape, and change it.
 
P

Paul Herber

I must be misunderstanding you-

"How about, as soon as you know the selection keep a record of all the
shapes in a shape collection, or even just a string list containing
all the shape names. "

do you mean as soon as I know the original selection, as in, the shape
that is wanted on every page? Does the string list contain the names
of the shapes I pasted? Because that's what I'm trying to get- the
name of the shape I pasted. All I want is to be able to paste a
shape, get the name of that pasted shape, and change it.

Sorry, yes, you need to handle the shape added event, that will give
you a reference to the new shape.
 
J

Jessica.Hromiko

Sorry, yes, you need to handle the shape added event, that will give
you a reference to the new shape.

Any idea how I handle the shape added event?:)
 
J

Jessica.Hromiko

Look in the Visio SDK, there are examples there.

A related question- can 2 shapes have the same name on different pages
within a document?

If they cannot have the same name, can I reference a shape without
referencing the page? For example, if I have a shape collection
containing 2 shapes that are on 2 different pages from one another...
Sheet.142 and Sheet.50. I want to delete all shapes in the
collection, so I need to delete these 2 shapes, which I could easily
do using a for loop. However, I've been using ActiveDocument.Pages
(i).Shapes to reference shapes... I don't want to have to go page by
page to delete these shapes- I want to be able to delete them by their
shape name no matter what page they are on within the document. Make
sense?

Can anyone help?

Thanks,
Jessie Hromiko
 
P

Paul Herber

A related question- can 2 shapes have the same name on different pages
within a document?

Yes, multiple shapes can have exactly the same name etc except they
are on different pages.

If we go back to the start of this thread, try creating and putting
these shapes into a shapes collection. Then you can loop through these
shapes (loop from end to beginning!) and delete each one without
reference to the page.
 
D

David Parker

Just a thought ...
If you are having multiple copies of the same shape, then why are you not
dropping a Master .. no paste required.? You can make a Master in code,
with the Master.Shapes(1).Name called what you want, then the Page.Drop
returns a Shape object ... and if the name of the Shape instance is not what
you originally set for the Shape, then it means that the shape already
exists on the Page so you can delete it immediately.
 

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