Well there comes a time when you need to make a table in word and you need to insert data in to it, so here is my quick version, its not the greatest bit of code but it does the following job :
- Creates a table
- Inserts text
That’s all nothing more, nothing less.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
Sub Macro3() ' Dim docActive As Document Dim tblNew As Table Dim celTable As Cell Dim intCount As Integer Set docActive = ActiveDocument Set tblNew = docActive.Tables.Add( _ Range:=docActive.Range(Start:=0, End:=0), NumRows:=6, _ NumColumns:=3) intCount = 1 For Each celTable In tblNew.Range.Cells celTable.Range.InsertAfter vbCrLf & " Text here 1" & vbLf & "text here 2" & vbLf & "Text here 3 " & vbCrLf ' celTable.Range.InsertAfter "Cell " & intCount intCount = intCount + 1 Next celTable ' tblNew.AutoFormat Format:=wdTableFormatColorful2, _ ' ApplyBorders:=True, ApplyFont:=True, ApplyColor:=True End Sub |
Handy links for this
https://msdn.microsoft.com/en-us/library/office/ff838470.aspx