Hi all,
I need to output tables and paragraph dynamically in the word document.
I tried the code below, but cursor does not move to next page and nothing is output on the second page. Could you please take a look?
thank you !
'Dim wdApp As Object
'Set wdApp = CreateObject("word.Application")
'Early Binding
Dim wdApp As Word.Application
Set wdApp = New Word.Application
With wdApp
.Visible = True
.Activate
.Documents.Add
With .Selection
.Tables.Add _
Range:=wdApp.Selection.Range, _
NumRows:=1, NumColumns:=3, _
DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitContent
'Set table format 3 rows
For counter = 1 To 12
.TypeText Text:="Cell " & counter
If counter <> 12 Then
.MoveRight Unit:=wdCell
End If
Next
End With
'Selection.GoTo What:=wdGoToBookmark, Name:="TC_Table"
Selection.GoTo What:=wdGoToPage, Which:=lNextPage
Selection.TypeText vbCrLf & vbCrLf
Selection.TypeText vbCrLf & vbCrLf
Selection.TypeText vbCrLf & vbCrLf
Selection.TypeText "This is test."
.Tables.Add _
Range:=wdApp.Selection.Range, _
NumRows:=1, NumColumns:=3, _
DefaultTableBehavior:=wdWord9TableBehavior, _
AutoFitBehavior:=wdAutoFitContent
'Set table format 3 rows
For counter = 1 To 12
.TypeText Text:="Cell " & counter
If counter <> 12 Then
.MoveRight Unit:=wdCell
End If
Next
End With