access shape by name

J

joseph

Hello
My word document contains two shapes.
How to define name for each shape in word and access them using vba.
other word access using sometimes like shapes("name1")....="Mytext"

sometimes i have confusion when i insert a new shape in document.
shape(1) becomes shape(2)
 
J

Jean-Guy Marcil

joseph was telling us:
joseph nous racontait que :
Hello
My word document contains two shapes.
How to define name for each shape in word and access them using vba.
other word access using sometimes like shapes("name1")....="Mytext"

sometimes i have confusion when i insert a new shape in document.
shape(1) becomes shape(2)

Sorry, I hit ALT-S before I was done... Anybody knows how to remove that
shortcut from OE? It happens a lot to me... butter fingers..

I was going to correct the code, with he Selection object you have to use
the ShapeRange property... Sorry about that.

Selection.ShapeRange(1).Name = "myName"

As I was writing, use the following code to refer to the shape later in your
code:

ActiveDocument.Shapes("theNameYouUsed").(Some method/property)....
like:
ActiveDocument.Shapes("myName").Fill.ForeColor = wdColorBlack
etc.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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