Hey guys,
I am having trouble with this macro. It loops but seems to loop and skip a record as it generates the word file. I am trying to create a mail merge where each record outputs its own .docx or .pdf.
Thanks in advance
I am having trouble with this macro. It loops but seems to loop and skip a record as it generates the word file. I am trying to create a mail merge where each record outputs its own .docx or .pdf.
Thanks in advance
Code:
Sub nextRecord()
Dim inputNumber As Long
Dim count As Long
inputNumber = InputBox("Input Number of Partners to loop")
count = ActiveDocument.MailMerge.DataSource.recordCount
'Partner = ActiveDocument.MailMerge.Fields("Partners").Value = .txtSurname
'print first page and subsequent using a loop
Call runMacro
Call UpdateAllFields
'Printer
'ActivePrinter = "Adobe PDF"
'Application.PrintOut fileName:="", Range:=wdPrintAllDocument, Item:= _
'wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
'wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
'PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
'PrintZoomPaperHeight:=0
'PDF Printer
'ActivePrinter = "Adobe PDF"
'Application.PrintOut fileName:="", Range:=wdPrintAllDocument, Item:= _
'wdPrintDocumentWithMarkup, Copies:=1, Pages:="", PageType:= _
'wdPrintAllPages, Collate:=True, Background:=True, PrintToFile:=False, _
'PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
'PrintZoomPaperHeight:=0
MyCounter = 0
'loop
Do Until MyCounter = inputNumber
ActiveDocument.MailMerge.DataSource.ActiveRecord = wdNextRecord
Call runMacro
Call UpdateAllFields
MsgBox (MyCounter)
MyCounter = MyCounter + 1
'Call fileName
Loop
End Sub