Hi,
I have found a code that could help my work a lot (http://www.wiseowl.co.uk/blog/s199/word-bookmarks.htm) , it copies excel values to a bookmarked word template.
This works well, however it cannot access the footers and the headers. I know lot of others had this problem before, but as I lack the knowledge (I have never used vba before) I only managed to put text in headers, but not cell values. So I would need what this code does, just I have some values that should go to the footer/header area. Is someone that could help me with this?
Option Explicit
'change this to where your files are stored
Const FilePath As String = "C:\Users\Desktop\MT\"
Dim wd As New Word.Application
Dim PersonCell As Range
Sub CreateWordDocuments()
'create copy of Word in memory
Dim doc As Word.Document
wd.Visible = True
Dim PersonRange As Range
'create a reference to all the people
Range("A1").Select
Set PersonRange = Range( _
ActiveCell, _
ActiveCell.End(xlDown))
'for each person in list �
For Each PersonCell In PersonRange
'open a document in Word
Set doc = wd.Documents.Open(FilePath & "CL template.docx")
'go to each bookmark and type in details
CopyCell "MT1", 1
CopyCell "MT2", 2
CopyCell "MT3", 3
CopyCell "MT4", 4
'save and close this document
doc.SaveAs2 FilePath & PersonCell.Value & " - MT letters" & ".docx"
doc.Close
Next PersonCell
wd.Quit
MsgBox "Created MTs 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 PersonCell.Offset(0, ColumnOffset).Value
End Sub
Bookmarks