How to compute text width in paragraph

G

Gary Hillerson

How can I compute the length in inches of a substring in a paragraph?

I need a function that takes a Paragraph object, and a string that's
part of the text of that paragraph, and tells me whether the string's
width in the document is more than 1/4 inch.

Any help appreciated.
 
J

Jezebel

There's no Word function that does this directly, but you could do it using
the Information() function: set a Range to point to your substring, then
check the horizontal position --

MyRange.Information(wdHorizontalPositionRelativeToPage)

Now make a Range that starts immediately after your substring and check its
position: the width of your substring is the difference between the two,
provided you're still on the same line. (You can check the vertical position
to confirm that.)
 
G

Gary Hillerson

Thanks so much;it worked perfectly, it was pretty easy, and I got to
learn about the Information property.

g
 

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