1
目标:为我的Excel文档中的每一行创建一个单独的Word页面(全部可以在同一个Word文档中)。在Excel中为每行创建单独的单词页面文档
第1行包含问题,第2-n行包含人们的回答。以下是我想要的输出:
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.
如果在Word输出中可能有问题(所有行1)加粗,那太棒了!
这是我现在正在使用的代码。
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
问题与当前代码:
- 我需要行1被重复用于每个响应。现在,代码只是将行的信息捆绑到一个段落中。
- 我希望代码是动态的,然后循环遍历所有列,而不必定义每一列。
- 我希望每个回复都在Word文档的单独页面上。
你到目前为止试过了哪些代码? – Chrismas007 2014-11-24 17:03:26
@ Chrismas007在原帖中发帖子。 – 2014-11-28 16:09:47
我的答案在下面更新。如果有效,请不要忘记接受。 – Chrismas007 2014-11-28 18:30:50