Hi people,
I have this code which I want to improve
i changed range an now i have :
How to copy all this ranges in separated word documents, save them and close at the end?
Thank you.
I have this code which I want to improve
Code:
Sub CopyToWord()
Dim objWord As Object
Dim objDoc As Object
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add(Template:= _
"[URL="file://\\xxx\vb\PetarTest\template.docx"]\\xxx\vb\PetarTest\template.docx[/URL]")
Set Ar = Worksheets("Sheet1").Range("A1:F" & Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row)
Ar.Copy
objDoc.Range.Paste
objWord.Visible = True
Set objDoc = Nothing
Set objWord = Nothing
End Sub
i changed range an now i have :
Code:
Sub CopyToWord()
Dim objWord As Object
Dim objDoc As Object
Dim i As Long
Dim LR As Long
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add(Template:= _
"[URL="file://\\xxx\vb\PetarTest\template.docx"]\\xxx\vb\PetarTest\template.docx[/URL]")
LR = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 0 To LR
Set Ar = Worksheets("Sheet1").Range(Worksheets("Sheet1").Cells((i * 36) + 1, 1), Worksheets("Sheet1").Cells((i * 36) + 36, 6))
Ar.Copy
'----Here i need your help----
Next i
Set objDoc = Nothing
Set objWord = Nothing
End Sub
How to copy all this ranges in separated word documents, save them and close at the end?
Thank you.
Last edited: