view
09-02-2009, 06:23 AM
Hello again all,
In this I'm trying to;
1) Insert a 3x4 table
2) Apply a style
3) Set the widths of the columns (to 20%, 40% and 40%)
4) Add the text for the headers.
I've managed to get 1, 2 and 4 working as I want. But I'm having some real problems with 3.
If I don't include any code todo with the widths, then the table is inserted fine, spans the width of the document (to the margins) and has all 3 columns the same width.
However, when I try to manipulate the width of the columns, it seems to be going horribly wrong.
This is the code I have so far;
With ActiveDocument
'...
Set myRange = .Bookmarks("Body").Range
.Tables.Add Range:=myRange, NumRows:=4, NumColumns:=3
.Tables(1).Style = "StyleTHD"
' --------------------------
.Tables(1).PreferredWidthType = wdPreferredWidthPercent
.Tables(1).PreferredWidth = 100
.Tables(1).Columns(1).Width = 20
.Tables(1).Columns(2).Width = 40
.Tables(1).Columns(3).Width = 40
' --------------------------
Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=1, Name:=""
Selection.TypeText ("Date")
Selection.MoveRight Unit:=wdCell
Selection.TypeText ("Aim")
Selection.MoveRight Unit:=wdCell
Selection.TypeText ("Activity")
Selection.MoveRight Unit:=wdCell
With the above code, it seems that the table width is set to 20% (of the document), then the columns are set as percentages of the table, resulting in a really small table squished to the left margin.
What I'm trying to achieve is the table to be full width of the document (not in the margins though), then the first column to be 20%, second and third both 40% of the full table width.
Any thoughts on how to solve this? Hope I've explained what I'm trying to do properly and shown what I'm doing so far.
Any help is greatly appreciated.
In this I'm trying to;
1) Insert a 3x4 table
2) Apply a style
3) Set the widths of the columns (to 20%, 40% and 40%)
4) Add the text for the headers.
I've managed to get 1, 2 and 4 working as I want. But I'm having some real problems with 3.
If I don't include any code todo with the widths, then the table is inserted fine, spans the width of the document (to the margins) and has all 3 columns the same width.
However, when I try to manipulate the width of the columns, it seems to be going horribly wrong.
This is the code I have so far;
With ActiveDocument
'...
Set myRange = .Bookmarks("Body").Range
.Tables.Add Range:=myRange, NumRows:=4, NumColumns:=3
.Tables(1).Style = "StyleTHD"
' --------------------------
.Tables(1).PreferredWidthType = wdPreferredWidthPercent
.Tables(1).PreferredWidth = 100
.Tables(1).Columns(1).Width = 20
.Tables(1).Columns(2).Width = 40
.Tables(1).Columns(3).Width = 40
' --------------------------
Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=1, Name:=""
Selection.TypeText ("Date")
Selection.MoveRight Unit:=wdCell
Selection.TypeText ("Aim")
Selection.MoveRight Unit:=wdCell
Selection.TypeText ("Activity")
Selection.MoveRight Unit:=wdCell
With the above code, it seems that the table width is set to 20% (of the document), then the columns are set as percentages of the table, resulting in a really small table squished to the left margin.
What I'm trying to achieve is the table to be full width of the document (not in the margins though), then the first column to be 20%, second and third both 40% of the full table width.
Any thoughts on how to solve this? Hope I've explained what I'm trying to do properly and shown what I'm doing so far.
Any help is greatly appreciated.