Re: Need help sizing table columns correctly
- From: "Rhino" <no.offline.contact.please@xxxxxxxxxx>
- Date: Sat, 11 Feb 2006 18:10:28 -0500
How? Do you mean that I should record this with the macro recorder and then
figure out what needs to change in my existing macro to match the new
recording? If so, I'm a little skeptical of that approach: I've been burned
several times now by the macro recorder not capturing things that I've done
while it was running.
Or have I misunderstood your suggestion?
--
Rhino
"Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx> wrote in message
news:O7A4zg1LGHA.1192@xxxxxxxxxxxxxxxxxxxxxxx
Create a table of the sort that you want and then make an autotext entry
out of it.
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
"Rhino" <no.offline.contact.please@xxxxxxxxxx> wrote in message
news:uQe03T0LGHA.1472@xxxxxxxxxxxxxxxxxxxxxxx
I need some help getting a macro working exactly the way I want. I've
looked in the Help but can't quite figure out what I need to do.
I'm creating a series of small tables, that will appear one after the
other. Each table will have two rows. The first of the two rows will have
4 columns, the second row will contain only one column.
I'd like each table to use all of the available width between the left
and right page margins, which are set at 60 points each. I want the first
three columns of the first row of each table to have a specific fixed
width. I'd like the fourth column of the first row of each table to get
whatever space is left over after the first three columns have been
written. The second row of each table should get the full available width
between the left and right page margins.
This is my current sub for creating the table and setting the desired
column widths:
=================================================================
Sub createTable()
'Create a two row, four column table.
Set newTable = ActiveDocument.Tables.Add(Range:=Selection.Range,
NumRows:=2, NumColumns:= _
4, DefaultTableBehavior:=wdWord9TableBehavior, AutoFitBehavior:= _
wdAutoFitFixed)
'Format the table. Set the column widths and merge the cells on the
second row into a single cell.
With newTable
If .style <> "Table Grid" Then
.style = "Table Grid"
End If
.AllowAutoFit = False
.PreferredWidthType = wdPreferredWidthPercent
.PreferredWidth = 100
.ApplyStyleHeadingRows = True
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = True
.ApplyStyleLastColumn = False
'Set widths of columns (in inches)
.Columns(1).Width = InchesToPoints(1.1)
.Columns(2).Width = InchesToPoints(1.2)
.Columns(3).Width = InchesToPoints(1.7)
.Columns(4).Width = InchesToPoints(3.2)
'Merge the cells on the second row into one cell
.Rows(2).Cells.Merge
End With
'Make sure table isn't split across pages.
Selection.Tables(1).Select
With Selection.ParagraphFormat
.KeepWithNext = True
End With
End Sub
=================================================================
This _almost_ does what I want but there are two things that I don't
like:
a. "AutoFitBehavior:=wdAutoFitFixed" in the 'set' statement and
".AllowAutoFit = False" seem to contradict one another; the 'set' seems
to be saying that I should use AutoFit while the 'with' seems to turn it
off. Should the 'set' be written differently to prevent the columns from
ever having had the ability to resize themselves?
b. I want the widths of the first 3 columns on the first row of each
table to be fixed at the sizes shown. I want the 4th column to
automatically get whatever space is left between the 3rd column and the
right margin without first having to calculate an actual length in
inches. I thought that by leaving the width of the 4th column
unspecified, it would get all of the remaining space but, in fact, it
gets quite a bit less than the available space, with the result that the
table is narrower than it needs to be and the right margin is much bigger
than I want in the area where the tables are written. How can I get that
behavior?
I've looked in the Help but I must be searching on the wrong keywords
because I can't find a clear answer to either problem.
I was going to do some 'trial and error' with the width of the 4th
column. I erased the line after the "=" on the line that sets column 4's
width but the other options never appear. I was hoping to see something
like "UseRemainingSpace". Shouldn't I be getting a list of options when I
do that? If yes, I must have something wrong in my VBE settings; can
someone tell me what I need to turn on?
If you can help me solve these last two problems, I think my document
will be absolutely perfect instead of just 98%.
--
Rhino
.
- Follow-Ups:
- Re: Need help sizing table columns correctly
- From: Doug Robbins - Word MVP
- Re: Need help sizing table columns correctly
- References:
- Need help sizing table columns correctly
- From: Rhino
- Re: Need help sizing table columns correctly
- From: Doug Robbins - Word MVP
- Need help sizing table columns correctly
- Prev by Date: Re: Need help sizing table columns correctly
- Next by Date: Re: Need to refine simple code ending in Wend
- Previous by thread: Re: Need help sizing table columns correctly
- Next by thread: Re: Need help sizing table columns correctly
- Index(es):
Relevant Pages
|