如何通过 excel vba 在 word 文档的新页面上添加文本
How to add text on new page in word doc via excel vba
如何在 word 文档的新页面上按行添加文本。即 excel 中的每一行都将出现在 word 文档的新页面上。
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
您可以从:
开始
objDoc.Range.Insertafter vbCr & Chr(12) & .Range("A" & i).Text
或者您可以自动执行邮件合并。
如何在 word 文档的新页面上按行添加文本。即 excel 中的每一行都将出现在 word 文档的新页面上。
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
您可以从:
开始objDoc.Range.Insertafter vbCr & Chr(12) & .Range("A" & i).Text
或者您可以自动执行邮件合并。