Determining length of line

L

livetohike

Word 2000
I want to use something other than the 3 characters provided as tab
leader options.

As an old C programmer, I outlined the algorithm I would use, but
don't know if VBA has the right methods.

If a method could return the 'length' of a line of text using a
variable width font and then subtract that from the total length
available (left margin to the leader tab), you could then divide that
length by the width of my leader character to determine how many to
insert.

I am just thinking out of the box ;-)

I imagine VBA can tell me the number of characters in a line, but for
a non-fixed-width font, that won't help. I need it in pixels, or
points, inches or some other "real" unit.

Then it would need to iterate through each line of the selection and
do the actual replacement.
Possible?
 
J

Jonathan West

livetohike said:
Word 2000
I want to use something other than the 3 characters provided as tab
leader options.

As an old C programmer, I outlined the algorithm I would use, but
don't know if VBA has the right methods.

If a method could return the 'length' of a line of text using a
variable width font and then subtract that from the total length
available (left margin to the leader tab), you could then divide that
length by the width of my leader character to determine how many to
insert.

I am just thinking out of the box ;-)

I imagine VBA can tell me the number of characters in a line, but for
a non-fixed-width font, that won't help. I need it in pixels, or
points, inches or some other "real" unit.

Then it would need to iterate through each line of the selection and
do the actual replacement.
Possible?

Yes, possible. You can get the horizontal position of the cursor (in points)
relative to the page by means of the
Selection.Information(wdHorizontalPositionRelativeToPage) property.
 
H

Helmut Weber

Hi,

Sub Test5bb()
Dim x As Single
Selection.ExtendMode = False
Selection.EndKey unit:=wdLine
x = Selection.Information(wdHorizontalPositionRelativeToTextBoundary)
MsgBox x
End Sub

See help on information,
then proceed to
Type Required WdInformation. The information type.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
H

Helmut Weber

Hi Jonathan,

just occurred to me:

Beware of paragraphs with left indentation. :)

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 

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