Measuring the Width of Text with VBA?

O

osirun

Me again!

Is there any easy way to measure the width of, e.g., a Heading Two
using VBA. (As opposed to measuring the character count, which is
easy but unreliable).

Basically I want to know if any given heading occupies one, two, or
three lines of the page...

Cheers,

Matthew
 
O

osirun

Another idea - is there any way I can tinker with

ActiveDocument.Range.Characters.Last.Information(wdVerticalPositionRelativeToPage)

so that it shows me how far down the page the last character of a
Heading Two might be?

At the moment it doesn't seem to work - or at least I get the same
value for every heading I try.
 
O

osirun

Aha! I think

ActiveDocument.Range.Characters.Last.Select
MsgBox Selection.Information(wdVerticalPositionRelativeToPage)

might do the trick!
 
H

Helmut Weber

Hi,

like that:

Sub Test7()
Dim rTmp As Range
Set rTmp = ActiveDocument.Range
With rTmp.Find
.Style = "Heading 1"
While .Execute
MsgBox rTmp.ComputeStatistics(wdStatisticLines)
MsgBox
rTmp.Characters.Last.Information(wdVerticalPositionRelativeToPage)
Wend
End With
End Sub

Beware of linebreaks by the newsreader.


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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