PDA

View Full Version : formatting Word tables via Excel macro



Quinn
03-16-2006, 10:11 AM
I'm using Excel to create word tables. See the code below (compliments of MDMacKillop) I am having trouble formatting the tables, though.

Option Explicit
Sub Tables()

'This code requires a referece to the Word object model
Dim Appword As New Word.Application
Dim Array1, Array2, X As Long

Set Appword = CreateObject("Word.Application")
Appword.Documents.Add

Array1 = Array(Range("A1:V1").Value)
Range("a15:a36").Value = Application.WorksheetFunction.Transpose(Array1)

For X = 1 To 3
Array2 = Array(Range("A1:V1").Offset(X, 0).Value)
Range("B15:B36").Value = Application.WorksheetFunction.Transpose(Array2)

Range("A15:B36").Copy

Appword.Selection.Paste
Appword.Selection.InsertBreak
Next
Appword.Visible = True

End Sub
I tried code such as:
Appword.Selection.Tables(1).Borders(wdBorderLeft).LineStyle = wdLineStyleDouble
etc. but can not get the .font and .alignment etc..
should I format before or after the break. thanks.

mdmackillop
03-16-2006, 02:11 PM
Appword.Visible = True
For X = 1 To 3
Appword.ActiveDocument.Tables(X).Select
With Appword.Selection.Tables(1)
With .Borders(wdBorderLeft)
.LineStyle = wdLineStyleDouble
.LineWidth = wdLineWidth050pt
.Color = wdColorAutomatic
End With
End With
Next