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
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