Hello, I am trying to run a macro in order to print my files from a mail merge to individual word files and I am using the following code that I have found online:
The problem is that the files are printed without the header and the footer. Is there any way to solve this please ? I looked at other tutorials online but I am really new to this VBA stuff and I can't seem to make it work, modifying anything in the code just gives me tons of errors and it's not working anymore.Option Explicit Const FOLDER_SAVED As String = "C:\Users\cbuja\Desktop\test\" Const SOURCE_FILE_PATH As String = "C:\Users\cbuja\Desktop\februarie wk9.xlsm" Sub TestRun() Dim MainDoc As Document, TargetDoc As Document Dim dbPath As String Dim recordNumber As Long, totalRecord As Long Set MainDoc = ActiveDocument With MainDoc.MailMerge '// if you want to specify your data, insert a WHERE clause in the SQL statement .OpenDataSource Name:=SOURCE_FILE_PATH, SQLStatement:="SELECT * FROM [Sheet1$]" totalRecord = .DataSource.RecordCount For recordNumber = 1 To totalRecord With .DataSource .ActiveRecord = recordNumber .FirstRecord = recordNumber .LastRecord = recordNumber End With .Destination = wdSendToNewDocument .Execute False Set TargetDoc = ActiveDocument TargetDoc.SaveAs2 FOLDER_SAVED & "Batch Disposition Checklist " & .DataSource.DataFields("Batch_Number").Value & " (RRPPMR)" & ".docx", wdFormatDocumentDefault TargetDoc.Close False Set TargetDoc = Nothing Next recordNumber End With Set MainDoc = Nothing End Sub
Thanks for your help !





Reply With Quote