I would like the document which is created from the code below named "Production [todays date]", To print automatically pages 2+, and then close.
Everything I have tried either acts on the original mail merge doc or produces an error. How would I go about this?
Thanks
Sub RunMailMerge()
Dim wdOutputName, wdInputName As String
wdOutputName = ThisWorkbook.Path & "\Production " & Format(Date, "d mmm yyyy")
wdInputName = ThisWorkbook.Path & "\Mm.docx"
Dim wdDoc As Object
Set wdDoc = GetObject(wdInputName, "Word.document")
wdDoc.Application.Visible = True
With wdDoc.MailMerge
.MainDocumentType = wdFormLetters
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
.Execute Pause:=False
End With
wdDoc.Application.Visible = True
wdDoc.Application.ActiveDocument.SaveAs wdOutputName
wdDoc.Close SaveChanges:=False
Set wdDoc = Nothing
If MsgBox("Production Complete" & vbNewLine & "Clear MailMerge?", vbYesNo + vbQuestion, "UKWC Production") = vbYes Then
Dim rngRange As Range
With Sheets("mastermm")
Set rngRange = .Range("3:40").EntireRow
End With
rngRange.Delete
ActiveWorkbook.Close (1)
Exit Sub
Else
ActiveWorkbook.Close (0)
Exit Sub
End If
End Sub
The document to be printed remains open
---------- Post added at 03:42 PM ---------- Previous post was at 03:19 PM ----------
ok, printing the right doc with "wdDoc.Application.activedocument.PrintOut" added after it saves the document. How would I set page range to 2+?
---------- Post added at 03:49 PM ---------- Previous post was at 03:42 PM ----------
Should deffinately think before I post. Trying to avoid printing an example record which no longer needs to be there. Solved and solved.
Bookmarks