The macro I have in excel reads data from every row and creates a word file for each row based on that data. The word file used as a template has bookmarks (values in columns are mapped to the bookmarks).
I got it to work for one row, but it won’t loop through all the rows. The code I’m using I got from:http://www.wiseowl.co.uk/blog/s199/word-bookmarks.htm
Here is my code:
Option Explicit
'change this to where your files are stored
Const FilePath As String = "C:\Files\"
Dim wd As New Word.Application
Dim SOPCell As Range
Sub CreateWordDocuments()
'create copy of Word in memory
Dim doc As Word.Document
wd.Visible = True
Dim SOPRange As Range
'create a reference to all the people
Range("A1").Select
Set SOPRange = Range(ActiveCell, ActiveCell.End(xlDown)).Cells
'for each person in list �
For Each SOPCell In SOPRange
'open a document in Word
Set doc = wd.Documents.Open(FilePath & "template.doc")
'go to each bookmark and type in details
CopyCell "sop", 0
CopyCell "equipment", 1
CopyCell "component", 2
CopyCell "step", 3
CopyCell "form", 4
CopyCell "frequency", 5
CopyCell "frequencyB", 5
'save and close this document
doc.SaveAs2 FilePath & "SOP " & SOPCell.Value & ".doc"
doc.Close
Next SOPCell
wd.Quit
MsgBox "Created files in " & FilePath & "!"
End Sub
Sub CopyCell(BookMarkName As String, ColumnOffset As Integer)
'copy each cell to relevant Word bookmark
wd.Selection.GoTo What:=wdGoToBookmark, Name:=BookMarkName
wd.Selection.TypeText SOPCell.Offset(0, ColumnOffset).Value
End Sub
You seem to miss the range parameter in your copyCell Sub