Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Measuring the Width of Text with VBA?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
osirun@gmail.com - 14 Mar 2008 21:31 GMT
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
osirun@gmail.com - 14 Mar 2008 22:16 GMT
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.
osirun@gmail.com - 14 Mar 2008 22:38 GMT
Aha!  I think

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

might do the trick!
Helmut Weber - 14 Mar 2008 23:08 GMT
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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.