Home » excel » How to add text on new page in word doc via excel vba

How to add text on new page in word doc via excel vba

Posted by: admin May 14, 2020 Leave a comment

Questions:

How do I add text row wise on new page in word doc. i.e. each row from excel will be on new page on word document.

Sub marine()

Dim i As Long, j As Long, fD As Long
Dim objWord As Object, objDoc As Object

With DATA

    fD = .Range("A" & .Rows.Count).End(xlUp).Row
    If fD = 1 Then MsgBox ("No data on Data worksheet."): Exit Sub

    Set objWord = CreateObject(“Word.Application”)
    Set objDoc = objWord.Documents.Add
    objWord.Visible = True

    For i = 2 To fD

          'How do I add text row wise on new page in word doc. i.e. each row from excel will be on new page on word document.

    Next i

    objDoc.SaveAs (ThisWorkbook.Path) '& "\Output.docx")

End With



End Sub
How to&Answers:

You might start with:

objDoc.Range.Insertafter vbCr & Chr(12) & .Range("A" & i).Text

Or you might automate a mailmerge.