Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 09-15-2022, 02:27 PM
macropod's Avatar
macropod macropod is offline Shrink to fit long merged name Windows 10 Shrink to fit long merged name Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

That could only be happening to your second example if it spanned more than one line. The code specifically tests how many lines the content in each cell spans. Perhaps you have an extraneous paragraph break/line break there? Or are you doing this in the mailmerge main document instead of to the output?

For a generalised mailmerge solution, you might use something like:
Code:
Sub MailMergeToDoc()
Application.ScreenUpdating = False
Dim Tbl As Table, Cll As Cell, Par As Paragraph, sCllWdth As Single, sParWdth As Single
With ActiveDocument
  With .Tables(1).Cell(1, 1)
      sCllWdth = .Width - .LeftPadding - .RightPadding
      With .Range.Paragraphs(1)
        sCllWdth = sCllWdth - .LeftIndent - .RightIndent
      End With
    End With
  End With
  .MailMerge.Execute
End With
With ActiveDocument
  For Each Tbl In .Tables
    For Each Cll In Tbl.Range.Cells
      If Len(Cll.Range) > 2 Then
        For Each Par In Cll.Range.Paragraphs
          With Par.Range
            sParWdth = .Characters.Last.Previous.Information(wdHorizontalPositionRelativeToPage) _
              - .Characters.First.Information(wdHorizontalPositionRelativeToPage)
            If sParWdth > sCllWdth Then .FitTextWidth = sCllWdth
            If .Characters.Last.Previous.Information(wdVerticalPositionRelativeToPage) > _
              .Characters.First.Information(wdVerticalPositionRelativeToPage) Then .FitTextWidth = sCllWdth
          End With
        Next
      End If
    Next
  Next
End With
Application.ScreenUpdating = True
End Sub
The above code processes cell content by paragraph, rather than just the whole cell. Not only does this code cater for wrapped lines, it also caters for cells whose content exceeds the cell width where someone has turned line-wrapping off.

The only caveat is that every intended new line in the cells is created by a paragraph break rather than a manual line break.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shrink to fit long merged name How to unmerge all merged cell and fill them with the merged values? Bumba Excel Programming 1 11-10-2019 11:36 AM
Shrink to fit long merged name Why my Docm file does not shrink in size? eduzs Word VBA 3 09-16-2018 04:13 AM
Shrink to fit long merged name Does Word automatically shrink graphics? jrasicmark Drawing and Graphics 1 05-06-2014 04:38 PM
Custom Animation: Faded Shrink? Dingeling PowerPoint 2 12-14-2011 02:14 AM
Possible to shrink .DOC file? uoficowboy Word 0 06-09-2010 10:13 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:19 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft