T
Terry
I have a template that contains a table consisting of 1 row and 7 columns.
The columns have been set to the witdths I required within the table. The
table has a Bookmark in the first row first column, POLine.
I am looping through a recordset and filling the cells, this appears to work
OK. However the column widths are lost. How do I keep the column widths
fixed.
Regards
If objWord.ActiveDocument.Tables.Count >= 1 Then
Set myTable = objWord.ActiveDocument.Tables(1)
myTable.PreferredWidth = 0
'Selection.Tables(1).Columns(1).PreferredWidth =
InchesToPoints(1.25)
'Selection.Tables(1).Columns(2).PreferredWidth =
InchesToPoints(5)
' hide borders
With myTable.Borders
.InsideLineStyle = wdLineStyleNone
.OutsideLineStyle = wdLineStyleNone
End With
End If
'''''' Fill the Cells
Dim i As Integer
Do Until rstOUT.EOF = True
i = rstOUT.AbsolutePosition + 1
With rstOUT
intRowCount = Format$(!SortOrder, "00")
strGoodsServices = !GoodsServices
strLineQuantity = Format$(!LineQuantity, "0")
strLineAgreedFeeExcVAT = "£" &
Format$(!PriceAgreedFeeExcVat, "0.00")
strLineVATPercent = Format$(!VatPercent, "0.00")
strLineVATAmount = "£" & Format$(!VATAmount, "0.00")
strLineAgreedFeeIncVat = "£" &
Format$(!PriceAgreedFeeIncVAT, "0.00")
'''' New row
objWord.ActiveDocument.Bookmarks("POLine").Range.Rows.Add
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=1).Range
.Bold = False
.InsertAfter Text:=intRowCount
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=2).Range
.Bold = False
.InsertAfter Text:=strGoodsServices
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=3).Range
.Bold = False
.InsertAfter Text:=strLineQuantity
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=4).Range
.Bold = False
.InsertAfter Text:=strLineAgreedFeeExcVAT
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=5).Range
.Bold = False
.InsertAfter Text:=strLineVATPercent
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=6).Range
.Bold = False
.InsertAfter Text:=strLineVATAmount
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=7).Range
.Bold = False
.InsertAfter Text:=strLineAgreedFeeIncVat
End With
End With
rstOUT.MoveNext
Loop
' make word document visible
objWord.Visible = True
The columns have been set to the witdths I required within the table. The
table has a Bookmark in the first row first column, POLine.
I am looping through a recordset and filling the cells, this appears to work
OK. However the column widths are lost. How do I keep the column widths
fixed.
Regards
If objWord.ActiveDocument.Tables.Count >= 1 Then
Set myTable = objWord.ActiveDocument.Tables(1)
myTable.PreferredWidth = 0
'Selection.Tables(1).Columns(1).PreferredWidth =
InchesToPoints(1.25)
'Selection.Tables(1).Columns(2).PreferredWidth =
InchesToPoints(5)
' hide borders
With myTable.Borders
.InsideLineStyle = wdLineStyleNone
.OutsideLineStyle = wdLineStyleNone
End With
End If
'''''' Fill the Cells
Dim i As Integer
Do Until rstOUT.EOF = True
i = rstOUT.AbsolutePosition + 1
With rstOUT
intRowCount = Format$(!SortOrder, "00")
strGoodsServices = !GoodsServices
strLineQuantity = Format$(!LineQuantity, "0")
strLineAgreedFeeExcVAT = "£" &
Format$(!PriceAgreedFeeExcVat, "0.00")
strLineVATPercent = Format$(!VatPercent, "0.00")
strLineVATAmount = "£" & Format$(!VATAmount, "0.00")
strLineAgreedFeeIncVat = "£" &
Format$(!PriceAgreedFeeIncVAT, "0.00")
'''' New row
objWord.ActiveDocument.Bookmarks("POLine").Range.Rows.Add
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=1).Range
.Bold = False
.InsertAfter Text:=intRowCount
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=2).Range
.Bold = False
.InsertAfter Text:=strGoodsServices
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=3).Range
.Bold = False
.InsertAfter Text:=strLineQuantity
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=4).Range
.Bold = False
.InsertAfter Text:=strLineAgreedFeeExcVAT
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=5).Range
.Bold = False
.InsertAfter Text:=strLineVATPercent
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=6).Range
.Bold = False
.InsertAfter Text:=strLineVATAmount
End With
With objWord.ActiveDocument.Tables(1).Cell(Row:=i,
Column:=7).Range
.Bold = False
.InsertAfter Text:=strLineAgreedFeeIncVat
End With
End With
rstOUT.MoveNext
Loop
' make word document visible
objWord.Visible = True