Can't make the document printout command work... I am running a mail merge, and that part works perfectly. My only issue is printing the doc after the mail merge runs. I have tried researching this on line, but have not been able to find anything similar. If I use, Printout Range:=Printcurrentpage everything works great, except it will only print the first page of 4 (obviously). But, if I use Printalldocument or printallpages, the print job seems to get stuck in a loop. The Word doc returns a message that says something about "Please wait...Word is trying to....." How can I code this so that it will: A. Print the doc B. Print the whole document
Here is the code...
Private Sub cmdprint_Click()
Dim Sheet As Worksheet, wsName As String, DataSource As String, WordPath As String
Dim WordApp As New Word.Application, WordDoc As Word.Document, StrName As String
With ActiveWorkbook
DataSource = .FullName
WordPath = .Path & "\MailMerge_DD220.docx"
wsName = .Sheets("dd220").Name
StrName = .Sheets("dd220").Range("C2").Text
SavePath = .Path & "\DD220 Forms\"
End With
With WordApp
.Visible = True
.DisplayAlerts = wdAlertsNone
Set WordDoc = .Documents.Open(WordPath, AddToRecentFiles:=False)
With WordDoc
'Select Data Source and Complete Mail Merge
With .MailMerge
.MainDocumentType = wdFormLetters
.Destination = wdSendToNewDocument
.OpenDataSource Name:=DataSource, ConfirmConversions:=False, ReadOnly:=False, nkToSource:=True,_
AddToRecentFiles:=False, PassWordDocument:="", PasswordTemplate:="",WritePassWordDocument:="",_
WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, SubType:=wdMergeSubTypeAccess, _
Connection:="Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=DataSource;Mode=Read;" & _
"Extended Properties=""HDR=YES;IME", SQLStatement:="SELECT * FROM `" & wsName & "$`", SQLStatement1:=""
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
.ActiveRecord = wdDefaultActiveRecord
End With
.Execute Pause:=False
End With
.Close SaveChanges:=False
End With
With .ActiveDocument
NewFileName = StrName & " - DD220 - " & Format(Date, "dd mmm yyyy") & ".docx"
.SaveAs savepath + NewFileName, FileFormat:=wdFormatXMLDocument, AddToRecentFiles:=False
WordApp.Application.DisplayAlerts = wdAlertsNone
.PrintOut Background = False ', , Range:=wdPrintAllDocument
.Close SaveChanges:=False
End With
.DisplayAlerts = wdAlertsAll
.Quit
End With
Set WordDoc = Nothing: Set WordApp = Nothing
End Sub