Office Word Programming >> Word Selection and Ranges - dimensions

by Simon Woods » Thu, 05 Apr 2007 22:17:03 GMT

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




Office Word Programming >> Word Selection and Ranges - dimensions

by Stefan Blom » Thu, 05 Apr 2007 22:33:34 GMT


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

--
Stefan Blom
Microsoft Word MVP




selected
Word
a
hold of.
window
width. I've
didn't









Office Word Programming >> Word Selection and Ranges - dimensions

by Simon Woods » Thu, 05 Apr 2007 22:53:35 GMT






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







Word Selection and Ranges - dimensions

by Stefan Blom » Tue, 10 Apr 2007 15:06:04 GMT

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





a
that
I'm
Watch
height
behind

Help
includes
of the
page but
or
the left
do the
to see









Similar Threads

1. Word 2003 Selection or Range Objects - Word Document management

2. Replace selection.range Word bug?

Hi,

For several years I've coped with this problem, but now I really want (need) 
a solution. I hope any of you can help me out.

What's the case, well in Word XP (and 97 and 2000), if I try to change the 
contents of a selected range in a table in a frame, it goes wrong. I've 
tried to replace the text directly, and tried first emptying the selection. 
In the text is for example '[test]' selected.

- When I use selection.range.text="" then Word leaves 't]' while it 
shouldn't.

- When I use selection.range.delete, surrounding spaces are also deleted. If 
I put a space in front and in back of '[test]' then it leaves just the one 
space instead of two.

- When I use selection.typetext text:="replacement", the spaces also get 
messed up.

The ever so strange thing is that it doesn't go wrong in a normal text, or 
in a normal table (not in a frame). When I say frame I mean a to a frame 
converted textbox (Or a table created in Word 2003 which is always a table 
within a frame?)

Extra info:

I search for 'codes' in the text and based on the contents of the 'codes' I 
replace them with a certain text. So I cannot use the standard Find/Replace 
functions. And somehwat I do use it, just a little split up, find first and 
do something and replace.

TIA!

Ronald Pothuizen


3. Selection/Range different in Word 2010 ??? - Word VBA

4. Excel - range selection won't turn off, cannot stop selecting cell

I have heard of Excel behaving this way with, (I believe it was) a logitech 
mouse with a wheel.  The user tries to use Excel despite reboots, and all it 
will allow the user to do is highlight cells, he/she is powerless to stop it. 

However, in this case, the user has no external mouse, but is using a Dell 
Latitude laptop with touchpad mouse.  Anyone know what else might cause this 
constant state of cell selection despite reboot?


5. Change print range default from all to selection - Word Document management

6. Bookmark Selection Range Problem

I use MFC VC++ 4.2
I have successful in getting all bookmarks and now I am trying to update them.

As the solution, I use Select() method that Bookmark class has:
if( m_Book.GetName() == "support" ){
			m_Book.Select();
			selObj.TypeBackspace();
			selObj.TypeText( pHistory->m_sSupportTantou );
		}

But now I have a problem with the range I guess, because each time I update 
the file, there are 2 / 3 bookmarks that did not updated.

Can you please help me with the Selection range?

I don't really understand and I set it to :

		long a = m_Book.GetStart();
		long b = m_Book.GetEnd();
		selObj.SetRange( a, b );

Thank you.

7. Range selection...

8. Range selection in Excel

Hello,

I am trying to let a user select a range by pressing a button in the edit
formula view) in VB for Excel. Is there a way to do this`?

Thanks,

Oliver