Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Jeff Deville
 
Posts: n/a
Default Fit Mail Merge Text to a certain Width

Ok, well I'll just post this as a solution for anyone who may be
interested. Here are the steps I am taking:

1. Set up your mail merge as usual
2. Use styles as a way of determining what text you need to resize.
For instance, I have a field called 'Name' that is what I am worried
will require resizing. So I created a style and used it exclusively
for this field.
3. Merge to a new document
4. In this new document, add this code to the VBA editor:

Public Sub PrintParagraphsToFormat()
Dim para As Paragraph
For Each para In ActiveDocument.Paragraphs
If para.Style = "INSERT THE STYLE NAME YOU CHOSE HERE" Then
para.Range.Select
While (IsTooLong(para))
Selection.Font.Size = Selection.Font.Size - 1
Wend
End If
Next
End Sub

Public Function IsTooLong(para As Paragraph) As Boolean
Dim rng As Range
Set rng = para.Range
Dim iHeightFront As Integer
Dim iHeightEnd As Integer
iHeightFront = rng.Information(wdVerticalPositionRelativeToPage)
rng.Collapse (WdCollapseDirection.wdCollapseEnd)
rng.MoveEnd Unit:=wdCharacter, Count:=-1
iHeightEnd = rng.Information(wdVerticalPositionRelativeToPage)
IsTooLong = iHeightFront iHeightEnd
End Function

What this code does is iterate through each paragraph in the document,
and check the style that is applied to that paragraph. If it matches
the one in question, then it checks the vertical position before and
after the paragraph. If these two values are not the same, then the
text must be wrapping to another line. So it lowers the font one size
at a time until the text fits on one line.

This is not a generic, pretty solution, but hopefully will help someone
get started.

 
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mail Merge Losing Data Scott May Mailmerge 1 November 1st 05 11:03 PM
Mail merge with Foreign Text Giovanni Mailmerge 0 September 22nd 05 01:00 PM
Mail Merge Using Contacts does not allow Rich Text Cjc Mailmerge 1 August 21st 05 06:09 AM
mail merge error message: "exceeds maximum width" clairemth04 Mailmerge 3 February 9th 05 12:01 AM
Can you use mail merge when the address field is inside a text box Fran Mailmerge 1 December 4th 04 04:28 PM


All times are GMT +1. The time now is 02:39 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"