https://stackoverflow.com/questions/27109839/macro-to-create-separate-word-page-for-each-row-in-excel-document

apple-touch-icon@2.png

Goal: create a separate Word page (can all be in the same Word doc) for each row in my Excel document.

Row 1 contains questions and Rows 2-n contain people's responses. Here's what I would like as an output:

Page 1 of Word Doc:

A1 Question

A2 Answer

B1 Question

B2 Answer

etc.

Page 2 of Word Doc:

A1 Question

A3 Answer

B1 Question

B3 Answer

etc.

If it's possible to have the questions (all of Row 1) bolded in the Word output, that would be fantastic!

Here's the code I'm working with now.

Sub WordDoc()
Dim TextEnter As String
Dim RowNum As Integer
Dim wordApp As Object
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

RowNum = 1

'Loop continues until a blank line is read; can be edited as necessary
Do While Range("A" & RowNum).Text <> ""
    TextEnter = Range("A" & RowNum).Text & " " & Range("B" & RowNum).Text & " " & Range("C" & RowNum).Text & " " & Range("D" & RowNum).Text & " " & Range("E" & RowNum).Text & " " & Range("F" & RowNum).Text & " " & Range("G" & RowNum).Text & " " & Range("H" & RowNum).Text
    'Puts text of row into a string adjust to the number of columns by adding more range
    wordApp.Selection.TypeParagraph 'Moves to the next line in word doc
    wordApp.Selection.TypeText Text:=TextEnter 'Enters Text to document
    RowNum = RowNum + 1 'Increments to the next row
Loop
End Sub

Problems with current code:

  1. I need Row 1 to be repeated for each response. The code, as it is now, just bundles the row's information together into a paragraph.
  2. I would like the code to be dynamic and loop through however many columns there are, without having to define each column.
  3. I would like each response to be on a separate page in the Word doc.