Hi,
I have a macro that does what I need it to, it takes data from an Excel table and writes the information in to word. At the moment in just creates a title based on the data and then creates and empty table underneath.
I want the imported text to be collapsable so have set it to use the Heading1 style which also works.
However, it is creating the table using the same font style, rather than normal. I've tried a couple of options like using wdStyleNormalTable and wdStyleNormal, but they either don't work, or change the formatting of the whole document.
Any thoughts would be appreciated.
I have a macro that does what I need it to, it takes data from an Excel table and writes the information in to word. At the moment in just creates a title based on the data and then creates and empty table underneath.
I want the imported text to be collapsable so have set it to use the Heading1 style which also works.
However, it is creating the table using the same font style, rather than normal. I've tried a couple of options like using wdStyleNormalTable and wdStyleNormal, but they either don't work, or change the formatting of the whole document.
Any thoughts would be appreciated.
VBA Code:
Const wdStyleHeading1 As Long = -2
Const wdStyleNormalTable As Long = -106
Const wdStyleNormal As Long = -1
For Each cell In rng
' Write the cell value as a heading in Word
With wdDoc
.Content.InsertAfter vbCrLf
.Content.InsertAfter cell.Value
.Content.InsertAfter vbCrLf
.Paragraphs.Style = wdStyleHeading1
End With
' Insert a table with 3 columns and 3 rows
With wdDoc.Tables.Add(wdDoc.Bookmarks("\EndOfDoc").Range, 3, 3)
For rowCounter = 1 To 3
.Style = wdStyleNormalTable
.Rows(rowCounter).SetHeight RowHeight:=20, HeightRule:=wdRowHeightExactly
.Borders.InsideLineStyle = 1 ' wdLineStyleSingle
.Borders.OutsideLineStyle = 1 ' wdLineStyleSingle
.Borders.InsideColor = wdColorBlack
.Borders.OutsideColor = wdColorBlack
Next rowCounter
End With
' Move to the next cell
Set rng = rng.Offset(1, 0)
Next cell