Re: Need help sizing table columns correctly
- From: "Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx>
- Date: Sun, 12 Feb 2006 20:30:12 +0100
Create an autotext entry of the table and then use vba to insert the
autotext.
--
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:u1Osd2$LGHA.1312@xxxxxxxxxxxxxxxxxxxxxxx
Okay, I see what you're saying and agree it would be a useful technique
for some situations. However, I want to do this work via a macro in this
case, which is why I posted to a VBA newsgroup in the first place.
I am building this document from scratch each time and I don't even want
to make Word GUI visible while the document is generated. There is a way
to do what I want by writing statements in a macro, right? Or is your
approach the only way that I can size my columns correctly?
--
Rhino
"Doug Robbins - Word MVP" <dkr@xxxxxxxxxxxxxxxxxx> wrote in message
news:ul2LAx6LGHA.2472@xxxxxxxxxxxxxxxxxxxxxxx
Yes, I think that you have mis-understood my suggestion. There is no
need for a macro. Here is what you do
1 Set up a single table the way the way you want it
2 Select that table and then from the Tools menu, select AutoCorrect
Options and then go to the AutoCorrect tab and it the "Replace text as
you type" section in the With area, you will see a couple of table cells.
In the Replace control to the left, type something like mytable, make
sure that the "Formatted text" radio button above the table cells is
select and then click on the Add button.
After doing this, whenever you type mytable and press the space bar, a
replica of your table will be inserted in its place.
--
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:Ofgv2A2LGHA.1180@xxxxxxxxxxxxxxxxxxxxxxx
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: Rhino
- 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
- Re: Need help sizing table columns correctly
- From: Rhino
- Re: Need help sizing table columns correctly
- From: Doug Robbins - Word MVP
- Re: Need help sizing table columns correctly
- From: Rhino
- Need help sizing table columns correctly
- Prev by Date: Re: Macro to remove date field, page number field
- Next by Date: Delete text in first cell of table in footer
- Previous by thread: Re: Need help sizing table columns correctly
- Next by thread: Re: Need help sizing table columns correctly
- Index(es):