Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-01-2015, 02:15 AM
Marco Marco is offline tables: fit only long lines to avoid line break Windows Vista tables: fit only long lines to avoid line break Office 2007
Novice
tables: fit only long lines to avoid line break
 
Join Date: Apr 2015
Posts: 15
Marco is on a distinguished road
Default tables: fit only long lines to avoid line break

Dear all, I am new to this forum.

I ask your help for the following question.
I have a table produced by mail marge from an access DB.
The column width is fixed and quite fitting that of the lines it will contain. However some lines may be a little longer and break, which is not wanted.



Since I guess there's no other way to get the result, I would like to add a VBA code to shrunk lines too long in the column width I chose.
The result is similar to the option "fit text" in the cell options, but this will also stretch short lines, while I only want to shrunk long ones.

Any suggestion?

Thanks, Marco
Reply With Quote
  #2  
Old 04-01-2015, 05:23 AM
gmayor's Avatar
gmayor gmayor is offline tables: fit only long lines to avoid line break Windows 7 64bit tables: fit only long lines to avoid line break Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

The following will probably do the trick.

Code:
Sub ShrinkCellTextToFit()
Dim orng As Range
Dim i As Long
Const iCol As Integer = 2        'the column to process

    If Not Selection.Information(wdWithInTable) Then
        MsgBox "Put the cursor in the table and try again"
        GoTo lbl_Exit
    End If
    For i = 1 To Selection.Tables(1).Rows.Count
        Set orng = Selection.Tables(1).Cell(i, iCol).Range
        orng.End = orng.End - 1
        Do Until orng.ComputeStatistics(wdStatisticLines) = 1
            orng.Font.Shrink
        Loop
    Next i
lbl_Exit:
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 04-02-2015, 06:18 AM
Marco Marco is offline tables: fit only long lines to avoid line break Windows Vista tables: fit only long lines to avoid line break Office 2007
Novice
tables: fit only long lines to avoid line break
 
Join Date: Apr 2015
Posts: 15
Marco is on a distinguished road
Default

Thanks gmayor, almost working

However I did not mention the following relevant notes

1) The cells do have more lines (number not fixed), so it is necessary to change the control alowing to exit the loop.
2) font size in each cell is not the same for all lines.

What I want is to avoid the break of originary lines. The final lines of my cell should be those broken by enter, and not those broken by their excessive length.
If easier to do, a proxy for this is result is avoiding the breaking of a word, since 99% of problematic lines are composed by a single word.

is it possible to get this?

Thanks
Marco
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
tables: fit only long lines to avoid line break keep several lines & images together without a page-break interfering lyle Word 1 02-11-2014 03:57 AM
Asian typography in text boxes - how to avoid lines starting with periods markpete Word 0 11-17-2012 01:45 PM
tables: fit only long lines to avoid line break Is there a way of keeping words together so that they don't break over two lines? Mayla Word 2 06-04-2012 07:37 AM
Break Pivot Into Multiple Tables Pramalot Excel 0 05-22-2012 05:21 AM
tables: fit only long lines to avoid line break Avoid merging tables b0x4it Word 4 06-14-2011 10:01 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:34 PM.


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