简体   繁体   中英

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

How do I add text row wise on new page in word doc. ie 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

You might start with:

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

Or you might automate a mailmerge.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM