How do I get the text on a specific row?

E

Erik L

Hi,

I would like to programatically get the text of a certain row in the
document (given a fixed row number counting from the top). What
objects/methods can I use to refer to that text?

Thanks for your time!

/Erik
 
E

Erik L

Hi! I guess I mean line, not row.

I have a letter Word template with a field of type macrobutton on top of the
first page in the document. This field is for the address of the letter. I
want to get the first line of the text the user writes in this field, i.e
the name part of the address. As far as I have noticed a field of this type
has no bookmark (like form fields) so I have no help from the field to refer
to the text.

Can I bookmark this text in some other way or just read the text of that
line from the document (assuming the address always start on let's say line
5 in the document)?

Hope you understand me this time! Thank you!
 
E

Erik L

Thanks! How do I define and bookmark the range to use then? Could you please
help with some example code? I'm totally new to vba...
 
H

Helmut Weber

Hi Erik,

a user cannot write in a macrobutton field, IMHO.

Anyway, if get you partially right, at least,
then you have a macro button connected to a macro.
You want the macro to get the text in line 5 of the
first page of your doument,
or the text in paragraph 5 of the doc.
If Your text looks like:




Mr. John Smith¶
then you want the text of paragraph 5.

If Your text looks like:
Some text
Some text
Some text
Some text
Mr. John Smith¶
then you want the text of line 5, probably.

Accessing paragraphs is much easier then accessing lines.

What is it? Paragraph 5 or line 5?
Try:
msgbox activedocument.paragraphs(5).range.text

Which would include the paragraph mark.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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