Ways to uniquely identify objects in Word/Powerpoint

J

JsjsLim

Hi,

I'm developing 3 addins for Word, Excel and Powerpoint using VSTO.

I would like to know if there are any best practices to uniquely
name/identify controls in the Word/Powerpoint addins as Excel does (Named
range)?

* Word (content controls, tables)
* PowerPoint (Shapes)

So far, I've been using the (Word) content control's Title, table's Id and
(PowerPoint) shape's Name properties to set/identify them. However, I can't
guarantee that these properties will not be changed by the user, or that
their values will be unique.

Why do I need this? My addins are supposed to be able to insert
shapes/controls/reports to the active document/presentation, and retrieve
them by their "names".

Any recommendations? Are there any other properties in a content
control/table/shape that I can use to store this additional information,
without worrying the another addin (or the user) will change this?

Thanks
 
C

Cindy M.

Hi JsjsLim,

Word content controls have an Id property that's read-only. Word generates
this (it's a GUID) when the content control is inserted in the document and it
cannot be changed.

You can insert a table in a content control, then insert content controls in
each cell and protect the outermost content control (the one into which the
table was inserted) from deletion and/or changing its content (only the
content controls in the cells could be editied in this case). Or you could
select the entire table then bookmark it. A power user could, conceivably
change or remove a bookmark, but only via the Bookmarks dialog box or by
deleting the entire table.

Shapes in the Office applications have a Name property that can only be
accessed via the object model. So if you assign a Name to a Shape that should
remain unique unless you run into a power user who starts changing names of
Shape using macros.
I'm developing 3 addins for Word, Excel and Powerpoint using VSTO.

I would like to know if there are any best practices to uniquely
name/identify controls in the Word/Powerpoint addins as Excel does (Named
range)?

* Word (content controls, tables)
* PowerPoint (Shapes)

So far, I've been using the (Word) content control's Title, table's Id and
(PowerPoint) shape's Name properties to set/identify them. However, I can't
guarantee that these properties will not be changed by the user, or that
their values will be unique.

Why do I need this? My addins are supposed to be able to insert
shapes/controls/reports to the active document/presentation, and retrieve
them by their "names".

Any recommendations? Are there any other properties in a content
control/table/shape that I can use to store this additional information,
without worrying the another addin (or the user) will change this?


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
S

Steve Rindsberg

JsjsLim said:
Hi,

I'm developing 3 addins for Word, Excel and Powerpoint using VSTO.

I would like to know if there are any best practices to uniquely
name/identify controls in the Word/Powerpoint addins as Excel does (Named
range)?

* Word (content controls, tables)
* PowerPoint (Shapes)

PowerPoint shapes have automatically generated Name and ShapeID properties.

The Name is supposed to be unique but won't always be, so you can't rely on it
100%.

[Cindy, as of PowerPoint 2007, the Name is exposed to users; the Selection
pane shows them the name AND allows them to change it.]

The ShapeID is more reliable but it's read-only. That may or may not be an
issue.

Shapes can also have .Tag collections; each .Tag is a Name/Value pair that can
be any strings you like.

eg:

oSh.Tags.Add "MyTagName", "Any string you like"
Debug.print oSh.Tags("MyTagName")

It'd be up to you to ensure that the tag values are unique and to write a
function that returns a reference to the shape whose tag you're looking for
(trivial).

You can have pretty much any number of tags you like on each shape. Slides
and Presentations can also have tags.

Caveat: There were a few bugs re tags getting lost between PPT 2007 and
previous versions; I think they've been fixed in SP1 or 2. You'll want to
test, if this'd be a problem.
 
J

JsjsLim

Hi Cindy and Steve,

Thanks for the reply!

I've actually been doing some of the things that you have mentioned: using
Shape's Name property (I actually did that *with* a tag where I throw in a
flag that allows me to check if the shape was added by my addin). Was simply
trying to find out if there's a simpler way to that.

As for the content controls, using a number will not work for me (or should
I say, for my client). I need to be able to identify them via a name. That is
why I've been using the Title property.

Another reason why I choose not to use a Content Control/Shape's id is
because I do not want the names to be tied to the control/shape. Eg,
Cut-Pasting controls/shapes, removing an existing control/shape and inserting
a new one with the same "name", and still be able to use it.

Any other ideas?

Thanks


Steve Rindsberg said:
JsjsLim said:
Hi,

I'm developing 3 addins for Word, Excel and Powerpoint using VSTO.

I would like to know if there are any best practices to uniquely
name/identify controls in the Word/Powerpoint addins as Excel does (Named
range)?

* Word (content controls, tables)
* PowerPoint (Shapes)

PowerPoint shapes have automatically generated Name and ShapeID properties.

The Name is supposed to be unique but won't always be, so you can't rely on it
100%.

[Cindy, as of PowerPoint 2007, the Name is exposed to users; the Selection
pane shows them the name AND allows them to change it.]

The ShapeID is more reliable but it's read-only. That may or may not be an
issue.

Shapes can also have .Tag collections; each .Tag is a Name/Value pair that can
be any strings you like.

eg:

oSh.Tags.Add "MyTagName", "Any string you like"
Debug.print oSh.Tags("MyTagName")

It'd be up to you to ensure that the tag values are unique and to write a
function that returns a reference to the shape whose tag you're looking for
(trivial).

You can have pretty much any number of tags you like on each shape. Slides
and Presentations can also have tags.

Caveat: There were a few bugs re tags getting lost between PPT 2007 and
previous versions; I think they've been fixed in SP1 or 2. You'll want to
test, if this'd be a problem.
 
C

Cindy M.

Hi Steve,
[Cindy, as of PowerPoint 2007, the Name is exposed to users; the Selection
pane shows them the name AND allows them to change it.]
Oh, lovely. That means it's going to propagate to Word in a future (the next?)
version... said:
The ShapeID is more reliable but it's read-only. That may or may not be an
issue.

Shapes can also have .Tag collections; each .Tag is a Name/Value pair that can
be any strings you like.


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
C

Cindy M.

Hi JsjsLim,
As for the content controls, using a number will not work for me (or should
I say, for my client). I need to be able to identify them via a name. That is
why I've been using the Title property.

Another reason why I choose not to use a Content Control/Shape's id is
because I do not want the names to be tied to the control/shape. Eg,
Cut-Pasting controls/shapes, removing an existing control/shape and inserting
a new one with the same "name", and still be able to use it.

Any other ideas?

It seems to me what you want is a bit contradictory. One the one hand, you don't
want the user to be able to access the information, on the other, your client
"requires" a name.

At this point, I'd consider working with the ID values in the code, and keeping
an array/collection of these paired with a "name" for the customer. Quite a bit
more work, maintaining the collection, but it seems only an approach like that
is going to be able to cover the requirements...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 
S

Steve Rindsberg

Hi Steve,
[Cindy, as of PowerPoint 2007, the Name is exposed to users; the Selection
pane shows them the name AND allows them to change it.]
Oh, lovely. That means it's going to propagate to Word in a future (the next?)
version... <Sigh> How many of your solutions did that interfere with?

0

Shape names in PPT are weird and unreliable so I stopped using them for anything
but quickie stuff years ago.

Example: While you're not allowed to have two shapes with the same name, under
some circumstances, PPT will happily such abominations on its own, then throw
hizzyfits if you try to change the name of either.
 

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