1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| Sub Facture_COT_LIC()
' Déclaration des variables
Dim iR As Integer
Dim i As Integer
Dim iAnnee As Integer
Dim oDocName As String
Dim oDocSave As String, oDocSave2 As String
Dim oDocPath As String
Dim oDS As MailMergeDataSource
Dim oDoc As Document
Dim oDocPDF As Document
' Affectation des objets
Set oDoc = ActiveDocument 'oDoc est le document WD ouvert
Set oDS = oDoc.MailMerge.DataSource ' oDS est la base XLS du doc WD
iR = oDoc.MailMerge.DataSource.RecordCount
'iR = oDoc.MailMerge.DataSource.RecordCount
'Debug.Print iR
For i = 1 To iR
With oDoc.MailMerge
'FILTRAGE DU PUBLIPOSTAGE WD, ON SELECTIONNE UN SEUL ENREGISTREMENT
.DataSource.FirstRecord = i
.DataSource.LastRecord = i
'ON DEFINIT LE RESULTAT DU FILTRE DU PUBLIPOSTAGE WD, COMME ENREGISTREMENT ACTUEL (=NUMPAGE ACTUEL)
.DataSource.ActiveRecord = i
'DEFINITION DU SUJET DE L'EMAILLING A PUBLIPOSTER
iAnnee = .DataSource.DataFields(1).Value
oDoc.MailMerge.MailSubject = "BMX CERNAY - FACTURE INSCRIPTION " & iAnnee & " - LICENCE + COTISATION"
'OK !! DEFINITION DU CHEMIN DE SAUVEGARDE
oDocPath = "C:\Users\BMX\Documents\BMX CERNAY\_06_COMPTA_BANQUE\_FACTURES\Annee_" & iAnnee & "\"
'OK !! DEFINITION DU NOM DE SAUVEGARDE
oDocName = .DataSource.DataFields(29).Value
oDocName = "Facture_" & oDocName
'OK !! DEFINITION DU TYPE DE FICHIER A SAUVEGARDER
oDocSave2 = oDocPath & oDocName
oDocSave = oDocPath & oDocName & ".pdf"
'SAUVEGARDE PC EFFECTUEE
ActiveDocument.SaveAs oDocSave, wdFormatPDF
'EXPORT DU PUBLIPOSTAGE EN PDF
'ActiveDocument.ExportAsFixedFormat oDocName & ".pdf", wdExportFormatPDF
ActiveDocument.ExportAsFixedFormat oDocSave, wdExportFormatPDF
'OK !! PREPARATION ET ENVOI DU PUBLIPOSTAGE
.MailAddressFieldName = "EMAIL"
.MailAsAttachment = True
.Destination = wdSendToEmail
.Execute
End With
ActiveDocument.ExportAsFixedFormat oDocSave, 17
'ActiveDocument.Close , False
Next i
End Sub |
Partager