Sub PrintLettera2(numerotessera As String)
'Mail merge e stampa su stampante di default
'On Error GoTo ErrorHandler
' open template in Word
Dim filepath As String
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Set WordApp = New Word.Application
filepath = ThisWorkbook.Path
Debug.Print filepath, numeroricevuta
With WordApp
.Visible = True
Set WordDoc = .Documents.Open(filepath & "Lettera Nuovi Soci.docx")
End With
'MailMerge selected records from table to Word document
With WordApp
.ActiveDocument.MailMerge.OpenDataSource Name:=filepath & "" & ThisWorkbook.Name, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, _
SQLStatement:="SELECT * FROM `rangesoci` WHERE [Numero Tessera] =" & numerotessera, SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
With .ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End With
WordDoc.Close SaveChanges:=False
WordApp.Quit
End Sub
*************
Sub PrintRicevuta(numeroricevuta As String)
'Mail merge e stampa su stampante di default
'On Error GoTo ErrorHandler
' open template in Word
Dim filepath As String
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Set WordApp = New Word.Application
filepath = ThisWorkbook.Path
Debug.Print filepath, numeroricevuta
With WordApp
.Visible = True
Set WordDoc = .Documents.Open(filepath & "stamparicevuta.docx")
End With
'MailMerge selected records from table to Word document
With WordApp
.ActiveDocument.MailMerge.OpenDataSource Name:=filepath & "" & ThisWorkbook.Name, _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, _
SQLStatement:="SELECT * FROM `rangericevute` WHERE [Numero] =" & numeroricevuta, SQLStatement1:="", _
SubType:=wdMergeSubTypeAccess
With .ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
End With
End With
WordDoc.Close SaveChanges:=False
WordApp.Quit
End Sub |