The code below adds Text and creates a Table. The code add the text "Appendix A" & "Total items: 10"
The problem is that it will add the text. When the table is created, it overwrites the text.
How can I add the table under/after the text?
I thought "ActiveDocument.Content.InsertParagraphAfter" would fix it.
strAppendixAName = "Appendix_A.docx"
strAppendixAPath = CurrentProject.Path
strAppendixAFullPath = strAppendixAPath & "\" & "Appendix_A.docx"
inttblAppendixAWorking =10
Dim objWord
Dim objDoc
Dim objSelection
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
Set objSelection = objWord.Selection
objWord.Visible = True
objDoc.SaveAs (strAppendixAFullPath)
objDoc.Select
objDoc.Activate
objDoc.ActiveWindow.Activate
objSelection.TypeText ("Appendix A" & vbCrLf & "Total items: " & inttblAppendixAWorking & vbCrLf & vbCrLf)
ActiveDocument.Content.InsertParagraphAfter
intRows = inttblAppendixAWorking
intCols = 2
'Create Table
Set tblAppA = objDoc.Tables.Add(Range:=objDoc.Range, _
NumRows:=intRows, _
NumColumns:=intCols)
tblAppA.Range.Font.Size = 12
tblAppA.Borders.Enable = True
tblAppA.Columns.PreferredWidthType = wdPreferredWidthPoints
tblAppA.Columns(1).PreferredWidth = CentimetersToPoints(3)
tblAppA.Columns(2).PreferredWidth = CentimetersToPoints(14#)
Set tblAppA = objDoc.Tables.Add(Range:=o
NumRows:=intRows, _
NumColumns:=intCols)
You can also try...
Open in new window