vba code to sdave word doc and repeat action

LeroyParnelly

New Member
Joined
Jun 14, 2015
Messages
2
Hello all, I'm very new to VBA and 1st post so bear with me please. I wrote/copied the following code which works well to open a word doc and fill out a few areas. I want it save that doc as a new file name, then repeat the actions based on cells in row 6 and so on until row is blank.

I think this might be a loop but never did one so don't know what to do now. Please let me know what else you may need to help. Thank you!!

Sub AutoFill_new_contract()
Dim objWord As Object
Dim ws As Worksheet

Set ws = ThisWorkbook.Sheets("New contract form")

Set objWord = CreateObject("Word.Application")

objWord.Visible = True

objWord.Documents.Open "F:\PO import process\06 Contract Review Online Rev. S draft.docx"

With objWord.ActiveDocument
.Bookmarks("Buyer").Range.Text = ws.Range("C5").Value
.Bookmarks("Contract_Number_Position").Range.Text = ws.Range("D5").Value
.Bookmarks("Cust_PO").Range.Text = ws.Range("A5").Value
.Bookmarks("Customer").Range.Text = ws.Range("B5").Value
.Bookmarks("Part_number").Range.Text = ws.Range("E5").Value
End With
Set objWord = Nothing
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,195,835
Messages
6,011,880
Members
441,651
Latest member
drewe2000

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top