Results 1 to 1 of 1

vba to print mail merge results

Threaded View

  1. #1
    Registered User
    Join Date
    07-03-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2007
    Posts
    41

    vba to print mail merge results

    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.
    Last edited by excelloser; 08-01-2012 at 10:37 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1