Access Word report - insert paragraph after table

DevAccess

Registered User.
Local time
Yesterday, 17:15
Joined
Jun 27, 2016
Messages
321
Hello,

I am generating report based on access data into word doc, I would like to insert table after few paragraphs I am having code as below.

First I am creating paragraph with some text and then I would like to have table with some content ( access data or may be hard coded ).

it is not working and gives error as below some time after modification of code it works but inserts the table at top of the document. also please let me know how to insert starting from page 2 of word document using vba.

Object doesn't support this property or method

wdapp.Visible = True
Set wddoc = wdapp.Documents.Add
Set oPara1 = wddoc.Content.Paragraphs.Add
With oPara1.Range
.InsertParagraphAfter
.Text = "test" & vbCr
.Paragraphformat.Alignment = 1
With .Font
.Name = "Verdana"
.Size = "9"
' .Bold = True
End With
End With


MsgBox "in1"
' Dim objRange, objTable As Object
Set objRange = wddoc.Range(wddoc.Paragraphs(3).Start, wddoc.Paragraphs(3).End - 1)
MsgBox "in"
wddoc.Tables.Add objRange, 9, 2
MsgBox "out"
Set objTable = wddoc.Tables(1)
objTable.Borders.Enable = False
objTable.Cell(1, 1) = "test1"
objTable.Cell(2, 1) = "test2"
objTable.Cell(2, 2) = "test3"
 
Here some pieces of our code. Maybe they will help

Code:
Dim apWord As Word.Application
Dim doc As Word.Document
Dim ppTable1 As Word.Table
Dim ppTable1Range As Word.Range

Set apWord = CreateObject("Word.application")
Set doc = apWord.Documents.Add("Normal", False, 0)

'The ranges is set to the end of the document and thats where the table will be inserted
Set ppTable1Range = doc.Content
ppTable1Range.Collapse Direction:=wdCollapseEnd
Set ppTable1 = doc.Tables.Add(Range:=ppTable1Range, NumRows:=NumberOfRecords + 1, NumColumns:=7) 'Extra row for the headers
 
It worked, thanks..
 

Users who are viewing this thread

Back
Top Bottom