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 / October 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Benjamino5 - 30 Oct 2007 15:41 GMT
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
Helmut Weber - 30 Oct 2007 16:53 GMT
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

Signature

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

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

Benjamino5 - 30 Oct 2007 23:14 GMT
Thanks, Helmut! Your approach worked perfectly.

Ben

> Hi,
>
[quoted text clipped - 17 lines]
> ' etc...
> End Sub

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.