I have 60 rows with 7 different tables, I am using office 2010.
Now I want to export the value of cells to the word document and paste them on a specific location and repeat it for 60 times with every time a different value.
Also I would like to save it with a cell value and that 60 times, so results would be 60 different letters saved with 60 different filenames that are in the cells.
I have manged to get to export the cells to the word document (1 time with bookmarks), but there is no loop that it will take the information from 60 cells and create 60 documents, and I need to make sure it will save 60 times with a different value of each cell. Really hope someone can help me with this as i am struggling for days now, please see my code:
Sub CertGenerator()
On Error GoTo errorHandler
Dim wdApp As Word.Application
Dim myDoc As Word.Document
Dim mywdRange As Word.Range
Dim Customer As Excel.Range
Dim Deliverynr As Excel.Range
Dim POnumber As Excel.Range
Set wdApp = New Word.Application
With wdApp
.Visible = True
.WindowState = wdWindowStateMaximize
End With
'Set the cell you want to copy'
Set myDoc = wdApp.Documents.Add(Template:="C:\Test\Authorisationform.doc")
Set Customer = Sheets("Sheet1").Range("A2")
Set Deliverynr = Sheets("Sheet1").Range("D2")
Set POnumber = Sheets("Sheet1").Range("E2")
Set Colnr = Sheets("Sheet1").Range("D2")
'Set the bookmark names'
With myDoc.Bookmarks
.Item("Customer").Range.InsertAfter Customer
.Item("Deliverynr").Range.InsertAfter Deliverynr
.Item("POnumber").Range.InsertAfter POnumber
.Item("Colnr").Range.InsertAfter Colnr
End With
'How to save word document'
With wdApp.ActiveDocument
.SaveAs ("C:\Test\Authorisationform1.doc")
.Close
End With
errorHandler:
Set wdApp = Nothing
Set myDoc = Nothing
Set mywdRange = Nothing
End Sub
Really hope someone can help me as I am already struggling for days now, and it seems nobody want to answer me....
Bookmarks