I am using a VBA macro to insert rows (two columns) in a word document. The problem is the inserted rows don't fill the entire page and all the columns don't have the same width:
My question is: how to give the same width to all the columns and to expand the table to fill the page width?
Here is my function:
Private Function CreateWordDoc(ByVal wrdApp As Word.Application, ByRef Objects() As OwnClass, ByVal sFilename As String, ByVal sPath As String)
Dim i As Integer
Dim wrdDoc As Word.Document
Dim MyObj As OwnClass
Dim wrdTppTable As Word.Table
Set wrdDoc = wrdApp.Documents.Add(sFilename, Visible:=True)
Set wrdTppTable = wrdDoc.Tables(2)
For i = 0 To UBound(Objects) - 1
Set MyObj = Objects(i)
' Add a row to the table and select it
wrdTppTable.Rows.Add.Select
' Work with the selected row
With wrdApp.Selection.Range
' Make sure the row is on two columns
.Cells.Split 1, 2, True
' Set the text font parameters
With .Font
.ColorIndex = wdBlack
.name = "Arial"
.size = 11
.Bold = False
End With
' Write text in the cell
.Text = MyObj.GetKey & ": " & MyObj.GetValue
' Then select the next cell in the row
.Next.Select
End With
' Work with the second column of the row
wrdApp.Selection.Cells.SetWidth 54, RulerStyle:=wdAdjustFirstColumn
With wrdApp.Selection.Range
With .Font
.ColorIndex = wdBlack
.name = "Arial"
.size = 11
.Bold = False
End With
' Write the cell
.Text = MyObj.GetId
End With
Next
End Function
Objects
is an array of objects I defined in my code. This is not relevant here. Your code makes a table with two columns and x rows but I want the table header to be only on one column. Should I do a merge of the first row at the end of the function? – Maxbester