How do I tell if text fits into a fixed-width table cell w/o wrapp

B

Benjamino5

I'm writing a macro to put a set of paragraphs (answer choices to a test
question) into a table. The idea is to reduce page count, so instead of
listing the answer choices a, b, c, and d on their own lines, they'll appear
in a two-row, two-column table that takes up less space.

The problem is that some questions' answer choices are simply too long to
fit into the columns of the table, and will wrap to the next line within
their cells--which looks bad and defeats the point (reducing page count).

So I need a test to see whether a set of answer choices is short enough to
fit into the fixed-width table. I can't count characters, because I'm using
Times New Roman, a proportional font, so an "M" takes up more space than an
"i."

I'm also using Word 2002/XP. I've heard that 2003 and 2007 offer more
fine-grained control over lines in VBA, but I'm stuck with 2002.

Thanks!
Ben
 
H

Helmut Weber

Hi,

like this, but don't expect it to work perfectly,
at least not from the start, you may have to adjust
it quite a bit, for example as far as cell borders
are concerned.

Sub Test400()
Dim p1 As Single ' position 1
Dim p2 As Single ' position 2
Dim l0 As Single ' length of a 1 line paragraph
Dim c0 As Single ' width of cell
With Selection.Paragraphs(1).Range
p1 = .Characters.First.Information(wdHorizontalPositionRelativeToPage)
p2 = .Characters.Last.Information(wdHorizontalPositionRelativeToPage)
l0 = p2 - p1
' MsgBox l0
End With
c0 = ActiveDocument.Tables(1).Range.Cells(1).Width
' etc...
End Sub

--
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