marreco
Member
Hi i try export data from excel to word, but display
Thank you!!
My file is in \Download and name is correct, way error?Run-time error '5491'
the requested member of the collection does not exist
Code:
Sub Direct_Mail()
Dim ws As Worksheet
Dim n As Long
Dim r As Long, rLast As Long
Dim c As Long, cLast As Long
Dim appWord As Word.Application
Dim doc As Word.Document
Set ws = ActiveSheet
Set appWord = CreateObject("Word.Application")
appWord.Visible = True
With ws
rLast = .Cells(.Rows.Count, "A").End(xlUp).Row
cLast = .Cells(1, .Columns.Count).End(xlToLeft).Column
For r = 2 To rLast
Set doc = appWord.Documents.Open(Filename:="C:\Users\marreco\Downloads\test.docx") 'this line yellow
For c = 1 To cLast
doc.Bookmarks(.Cells(1, c)).Range.Text = .Cells(r, c)
Next c
n = n + 1
doc.SaveAs2 Filename:="C:\Users\marreco\Downloads\" & Format(n, "000"), FileFormat:=wdFormatXMLDocument
doc.Close
Next r
End With
End Sub
Thank you!!