Word Selection and Ranges - dimensions

S

Simon Woods

Hi

Is there a way to find out programmatically the dimensions of a selected
range. Obviously if I select a range of text and insert a textbox, Word
knows how big to make that textbox and places all that text into the a
correctly sized textbox. That is the information I'm trying to get hold of.

I'm looking at the active Selection and Range objects in the Watch window
but there's nothing obvious to give a clue as to the height and width. I've
tried recording a macro to see what goes on behind the scenes but it didn't
give me much help.

Thanks

Simon
 
S

Simon Woods

in message
Stefan said:
A range is defined by its Start and End properties; see Word VBA Help
and http://word.mvps.org/FAQs/MacrosVBA/index.htm.

Thanks Stefan.

As I'm trying to get the dimensions of the range but the range includes
images as well as text. I wondered whether I could get the position of the
start char on the page and get the position of the end char on the page but
there's a problem if there is a graphic which is locate to the right or
bottom of the last char. Similar is there is a graphic situated to the left
or top of the start char.

Am I missing something in what you're suggesting. Or will I need to do the
math and work out the position of inline shapes relative to the text to see
if either of these scenarios apply?

Thanks

Simon
 
S

Stefan Blom

A range in itself does not have a "size" other than its start and end
properties; the actual space it occupies depends on the size of text
(including any inline objects).

As far as I know, the only way to get the position of the insertion
point on a page is to use the Information property:

x = Selection.Information(wdHorizontalPositionRelativeToPage)
y = Selection.Information(wdVerticalPositionRelativeToPage)

--
Stefan Blom
Microsoft Word MVP


in message
 

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