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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| Private Sub Fusion2_Click()
Dim file1 As String
Dim file2 As String
Dim File3 As String
Dim outPath$
outPath = CurrentProject.Path & "\" & Me.Annee & "\" & Me.NOAffaire & "\RapportFinal" & Me.NOAffaire & ".pdf"
file1 = CurrentProject.Path & "\" & Me.Annee & "\" & Me.NOAffaire & "\Rapport" & Me.NOAffaire & ".pdf"
file2 = Me.pdf2
File3 = Me.Pdf3
If Me.Pdf3 = "" Then
MsgBox "Merci d'attendre la fin du process"
Dim oPDF As PdfCreatorObj
Set oPDF = New PdfCreatorObj
oPDF.AddFileToQueue file1
oPDF.AddFileToQueue file2
Debug.Print "oPDF isinstancerunning: " & oPDF.IsInstanceRunning ' close Excel and open if true.
'On Error GoTo EndSub ' this is commented out for debuging purposes
Dim q As PDFCreator_COM.JobQueue
Set q = New PDFCreator_COM.JobQueue
'q.ReleaseCom
q.Initialize
q.WaitForJobs 3, 10
Debug.Print "q.Count: " & q.Count ' here it prints either 1 or 2. Should always be 2.
Dim Ret As Long
If q.Count < 3 And Ret < 6 Then
q.Clear
q.ReleaseCom
Ret = Ret + 1 'count the number of times this action returned without proceeding
'GoTo Top
ElseIf Ret >= 6 Then
MsgBox "The merge PDF return a error."
outPath = CurrentProject.Path & "\" & Me.Annee & "\" & Me.NOAffaire & "ERROR_MERGE.pdf"
End If
q.MergeAllJobs
Dim job As PDFCreator_COM.printJob
While q.Count > 0
Set job = q.NextJob
job.SetProfileByGuid ("DefaultGuid")
job.ConvertTo (outPath)
Debug.Print job.IsFinished
Debug.Print job.IsSuccessful
Debug.Print "q.Count3: " & q.Count
Wend
'EndSub:
'q.ReleaseCom 'mis en bas
MsgBox "Le rapport est prêt dans le dossier LaboRapport de l'affaire, le mail va être préparé dans outlook"
'Envoi du rapport pdf par mail
Dim objOutLook As Object
Dim objOutlookMsg As Object
Set objOutLook = New Outlook.Application
Set objOutlookMsg = objOutLook.CreateItem(0)
objOutlookMsg.To = Me.Mail 'destinataire
objOutlookMsg.CC = DLookup("[Copie]", "EnvoiMail", "[NomMail] = 'Rapport'") 'cc
'objOutlookMsg.BCC = TxtBCC 'cc caché
objOutlookMsg.Subject = Me.Nomaffaire & "//" & Me.NOAffaire 'sujet
objOutlookMsg.Body = DLookup("[TexteMail]", "EnvoiMail", "[NomMail] = 'Rapport'") 'message
objOutlookMsg.Attachments.Add CurrentProject.Path & "\" & Me.Annee & "\" & Me.NOAffaire & "\RapportFinal" & Me.NOAffaire & N° & ".pdf" 'CheminPJ
objOutlookMsg.display
EndSub:
q.ReleaseCom
MsgBox "Le mail est prêt"
Else
MsgBox "Merci d'attendre la fin du process"
oPDF.AddFileToQueue file1
oPDF.AddFileToQueue file2
oPDF.AddFileToQueue File3
Debug.Print "oPDF isinstancerunning: " & oPDF.IsInstanceRunning ' close Excel and open if true.
'On Error GoTo EndSub ' this is commented out for debuging purposes
'Dim q As PDFCreator_COM.JobQueue
'Set q = New PDFCreator_COM.JobQueue
'q.ReleaseCom
q.Initialize
q.WaitForJobs 3, 10
Debug.Print "q.Count: " & q.Count ' here it prints either 1 or 2. Should always be 2.
If q.Count < 3 And Ret < 6 Then
q.Clear
q.ReleaseCom
Ret = Ret + 1 'count the number of times this action returned without proceeding
'GoTo Top
ElseIf Ret >= 6 Then
MsgBox "The merge PDF return a error."
outPath = CurrentProject.Path & "\" & Me.Annee & "\" & Me.NOAffaire & "ERROR_MERGE.pdf"
End If
q.MergeAllJobs
While q.Count > 0
Set job = q.NextJob
job.SetProfileByGuid ("DefaultGuid")
job.ConvertTo (outPath)
Debug.Print job.IsFinished
Debug.Print job.IsSuccessful
Debug.Print "q.Count3: " & q.Count
Wend
'EndSub:
'q.ReleaseCom 'mis en bas
MsgBox "Le rapport est prêt dans le dossier LaboRapport de l'affaire, le mail va être préparé dans outlook"
'Envoi du rapport pdf par mail
Set objOutLook = New Outlook.Application
Set objOutlookMsg = objOutLook.CreateItem(0)
objOutlookMsg.To = Me.Mail 'destinataire
objOutlookMsg.CC = DLookup("[Copie]", "EnvoiMail", "[NomMail] = 'Rapport'") 'cc
'objOutlookMsg.BCC = TxtBCC 'cc caché
objOutlookMsg.Subject = Me.Nomaffaire & "//" & Me.NOAffaire 'sujet
objOutlookMsg.Body = DLookup("[TexteMail]", "EnvoiMail", "[NomMail] = 'Rapport'") 'message
objOutlookMsg.Attachments.Add CurrentProject.Path & "\" & Me.Annee & "\" & Me.NOAffaire & "\RapportFinal" & Me.NOAffaire & N° & ".pdf" 'CheminPJ
objOutlookMsg.display
MsgBox "Le mail est prêt"
End If
End Sub |
Partager