![]() |
|
|
|
#1
|
|||
|
|||
|
I have just spent about half an hour to create a Word Template that was a 4 cell table which I wanted to fit to an A4 page. About 10 minutes of this was trying to find an easy solution in the help files which provided no joy.
There must be a way to insert a table on a page defining the number of rows and columns and have it autofit the page where it is being inserted. Any solutions? |
|
#2
|
||||
|
||||
|
Hi boutells,
Nothing built-in, though the default width fits the page margins (plus whatever internal cell margins the table has). However, you could insert the table, then format its height with a macro. The following macro fits all selected tables to the height of the page in the section in which they appear. Whether the tables actually print that way depends on whether there is anything else on the same pages: Code:
Sub TableFit()
Application.ScreenUpdating = False
Dim oTopMargin As Single, oBottomMargin As Single, oBottomLine As Single
Dim oPageHeight As Single, oPrintHeight As Single, oRowHeight As Single
Dim oTable, oCell As Cell, i As Integer
If Selection.Tables.Count = 0 Then Exit Sub
For i = 1 To Selection.Tables.Count
oTable = Selection.Tables(i)
oBottomLine = 0
With oTable
For Each oCell In oTable.Rows(oTable.Rows.Count).Cells
If .Borders(wdBorderBottom).LineWidth > oBottomLine Then _
oBottomLine = .Borders(wdBorderBottom).LineWidth
Next
With .PageSetup
oTopMargin = .TopMargin
oBottomMargin = .BottomMargin
oPageHeight = .PageHeight
End With
oPrintHeight = oPageHeight - oTopMargin - oBottomMargin - oBottomLine / 8 - 1
oRowHeight = oPrintHeight / .Rows.Count
With .Rows
.Height = oRowHeight
.HeightRule = wdRowHeightExactly
End With
End With
Next
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
That works very well. Thank You
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to save the current page in a new file with all the page settings (header, footer | Jamal NUMAN | Word | 6 | 03-15-2012 03:27 PM |
MS Word, page goes to next page when entering data on previous page
|
munna94 | Word | 2 | 12-30-2010 08:12 AM |
Auto-Format Tables of Contents/Figures
|
judicial85 | Word | 3 | 12-25-2010 02:02 AM |
Page break inside tables.(word 2003)
|
englund33 | Word Tables | 1 | 06-15-2010 02:00 AM |
| Auto-updating basic math functions & cross-referencing tables | FranklinBluth | Word Tables | 13 | 11-19-2009 10:26 AM |