Excel VBA Macro: Create Multiple Word Documents at Once

preview_player
Показать описание
Excel VBA Macro: Create Multiple Word Documents at Once

From Worksheet:

SERVICE AGREEMENT
This Service Agreement is made between
The Client agrees to pay
Both parties agree to the terms outlined in this Agreement
and will cooperate to ensure satisfactory completion of the services.

Code:

Sub batch_word_template()

Dim objWord As Object
Dim objDoc As Object
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim row_count As Integer
Dim i As Integer

Set ws1 = ThisWorkbook.Sheets("Agreement")
Set ws2 = ThisWorkbook.Sheets("Client List")

ws2.Activate
row_count = ws2.Cells(Rows.Count, 1).End(xlUp).row

For i = 2 To row_count

Set objWord = CreateObject("Word.Application")
objWord.Visible = True

Set objDoc = objWord.Documents.Add
objDoc.SaveAs "C:\Users\greggowaffles\Documents\Youtube Videos\" & _
"Test\Service Agreements\Servive Agreement_" & _
ws2.Cells(i, 1).Text & "_" & ws2.Cells(i, 3).Text & ".docx"

With objWord
.Activate
ws2.Cells(i, 1).Text & " from " & ws2.Cells(i, 2).Text & _
", and " & ws2.Cells(i, 3).Text & "."
ws2.Cells(i, 4).Text & "for these services."
ws1.Range("A5").Text

End With

Next i

Set objDoc = Nothing
Set objWord = Nothing

End Sub

#excelvba #excelmacro #excelvbatutorial
Рекомендации по теме
Комментарии
Автор

Greg Hi, just wanted to say. Your videos are the only source of proper information for me. Everyime ! so useful, please keep them coming !!

SonofAnarchyy
Автор

Very useful Greg.. Please help in this... How can we make the amount in Bold letters.
Please

nixnews