I have been trying to solve this 'simple' problem but can't find the solution to the problem.
I am trying to generate up a powershell script to run a MS-WORD mailmerge and export the document (ideally as a pdf) to a specific file location. The mailmerge run successful but instead of generating a new document it just prints to the default printer. I would like it to generate up a new document so I can then save it to the supplied destination.
$DocumentName = 'MailMerge.docx'
$OutputFilename = 'Output.pdf'
$word=new-object -com Word.Application
$word.Visible = 'True'
$doc=$word.Documents.Open($DocumentName)
$doc.WdMailMerge.Destination.wdSendToNewDocument
$doc.Mailmerge.Execute()
$word.ActiveDocument.SaveAs([ref] $Outputfilename, [ref] 17)
$Doc.close()
$word.Quit()
I am guessing I am doing something wrong with the mailmerger destination, but I am going round in circles.
Thanks you in advance for any help you can give. (First time posting, please be gentle)
[edit] There is always something you important you forget. When stepping through this, it generates the mailmerge print before it gets to the line to save the document. When the save kicks in it is a single page document renaming the original mail merge.