Pasting excel rows to Word

kltinaheart

New Member
Joined
Apr 20, 2018
Messages
14
Hey all,

at my wits end. found this code online and was not successful in reworking it.

What I want is for Groups of rows to be pasted on their own individual Word Page.
I already successfully moved my excel rows into groups, separated by 1 blank row, so I figure the best way to do this is every time the code sees a blank row, it moves the next group of rows into their own Word Page. (though if you prefer we can separate by group ID number)
with the code below, I have only successfully moved each cell in A to its own word page.
Help please!!!!!!!!!!

Code:
Sub WordDoc()
    Dim TextEnter As String
    Dim RowNum As Integer
    Dim wordApp As Object
    Dim LastRow, LastCol, CurRow, CurCol As Long

    Set wordApp = CreateObject("word.application") 'Takes the object wordApp and assigns it as a Microsoft Word application
    wordApp.Visible = True 'Word application is visible
    'Adds a new document to the application
    wordApp.Documents.Add _
    Template:="", _
    NewTemplate:=False
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
    LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
    'For... Next Loop through all rows
    For CurRow = 2 To LastRow
        TextEnter = ""
        'For... Next Loop to combine all columns (header and answer) for given row into string
        For CurCol = 1 To LastCol
            TextEnter = TextEnter & Cells(1, CurCol).Value & vbCrLf & Cells(CurRow, CurCol).Value & vbCrLf
        Next CurCol
        wordApp.Selection.TypeParagraph 'Moves to the next line in word doc
        wordApp.Selection.TypeText Text:=TextEnter 'Enters Text to document
        wordApp.Selection.InsertBreak Type:=7 ' wdPageBreak
    Next CurRow

End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,214,375
Messages
6,119,164
Members
448,870
Latest member
max_pedreira

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top