Hello, I'm using Excel VBA code to create a MS Word document, based on a Word template.
I created table using Set objTable = wDoc.Tables(1). All works fine, but I need to position this table in specific spot within my document.
So I created a label {table1_here} in Word template. I find this label using wDoc.Application.Selection.Find.Text = "{table1_here}", but it seems that wDoc.Application.Selection = "ABC" can only replace label with a string, and I cannot do for example wDoc.Application.Selection = objTable.
So in my Word template I have;
line 1
line 2
{table1_here} (I want whole table to go here)
line 10
etc
How can I do this? Any help is much appreciated.
Dim wApp As Object 'Word.Application
Dim wDoc As Object 'Word.Document
Dim objRange As Object
Dim objTable As Object
Dim wdFormatXMLDocument As Integer
Set wApp = CreateObject("Word.Application")
wApp.Visible = False
wApp.DisplayAlerts = False
Set wDoc = wApp.Documents.Open(Filename:="word template.dotx", ReadOnly:=True)
wDoc.Application.Selection.Find.Text = "{table1_here}"
wDoc.Application.Selection.Find.Execute
Set objRange = wDoc.Range
wDoc.Tables.Add objRange, 20, 10
Set objTable = wDoc.Tables(1)
'wDoc.Application.Selection = "ABC" '<----------------------
wDoc.Application.Selection = objTable '<-----------------------
wDoc.Application.Selection.EndOf
Bookmarks