How can I give meaningful names to word objects?

S

Simon Kearns

For example: tblMyTable instead of tables(1)

I don't mean:
dim tblMyTable
Set tblMyTable = ActiveDocument.Tables(1)

I mean rather the same way you give name to controls on forms.
e.g. txtLastName instead of TextBox1

Thanks
Simon
 
J

Jonathan West

Simon Kearns said:
For example: tblMyTable instead of tables(1)

I don't mean:
dim tblMyTable
Set tblMyTable = ActiveDocument.Tables(1)

I mean rather the same way you give name to controls on forms.
e.g. txtLastName instead of TextBox1

Hi Simon,

In short, you can't. The best you can do is mark a table with a bookmark and
then work from that, like this


Dim tblMyTable
Set tblMyTable =
ActiveDocument.Bookmarks("MyMeaningfulBookmark").Range.Tables(1)
 
S

Simon Kearns

Hi Jonathan.
OK. That's Bad.

I need to populate a 'tree diagram' (like a family tree for example) with
Excel data and later insert it into a powerpoint presentation.
I was planning on using text boxes connected by drawn lines to make the
tree. There would be 10-12 of them and they need to be able to be moved
around sometimes. So the text boxes would be distributed vertically and
horizontally.
Does word name objects based on location or creation order? Does the
numbering change (e.g. if I move the box around)? Maybe a table would work
better? We are trying to use word to take advantage of formatting features
and to keep code out of a distributed PowerPoint presentaion but maybe word
is not the application for this job?
Anyway, these are things that I will go away and ponder but any thoughts
most appreciated.
Cheers
Simon
 
J

Jean-Guy Marcil

Simon Kearns was telling us:
Simon Kearns nous racontait que :
Hi Jonathan.
OK. That's Bad.

I need to populate a 'tree diagram' (like a family tree for example)
with Excel data and later insert it into a powerpoint presentation.
I was planning on using text boxes connected by drawn lines to make
the tree. There would be 10-12 of them and they need to be able to be
moved around sometimes. So the text boxes would be distributed
vertically and horizontally.
Does word name objects based on location or creation order? Does the
numbering change (e.g. if I move the box around)? Maybe a table would
work better? We are trying to use word to take advantage of
formatting features and to keep code out of a distributed PowerPoint
presentaion but maybe word is not the application for this job?
Anyway, these are things that I will go away and ponder but any
thoughts most appreciated.
Cheers
Simon

This is different from naming tables (which can't be named).

You can name a textbox if you create it through VBA.
For example:

'_______________________________________
Const TxtBx As String = "TextBox"
'_______________________________________
Sub CreateBox()

Dim MyTextBox As Shape

Set MyTextBox = ActiveDocument.Shapes. _
AddTextbox(msoTextOrientationHorizontal, 180#, _
144#, 198#, 135#)

With MyTextBox
.Name = TxtBx
.TextFrame.TextRange.Text = "Text box #1."
End With

End Sub
'_______________________________________

'_______________________________________
Sub DeleteBox()

ActiveDocument.Shapes(TxtBx).Delete

End Sub
'_______________________________________

--
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