Re : code vba "envoyer recevoir" outlook
re bonjour à tous
Finalement j'ai une solution qui "marche" avec l'inconvénient, qu'après une dizaine de secondes, j'ai un message d'erreur que la synchro des comptes avec abonnement a échouée. Je ne voit pas le rapport....
La solution consiste à faire " manuellement " la réduction de la fenêtre Outlook , comme Microsoft est très gentil pour le dire, j'ai donc taper pleins de raccourcis jusqu'à trouver mon bonheur...le voici :
Dim X As String
Dim Y As String
Dim Z As String
Dim i
Dim nomUtilisateur As String
Dim CheminDuFichier As String
Dim OutlookApp As Object
Dim OutlookMail As Object
Dim EMail As String
Set OutlookApp = CreateObject("Outlook.Application")
Set OutlookMail = OutlookApp.CreateItem(ol_MailItem)
If OutlookOuvert = False Then i = Shell("Outlook", vbHide) ' de YALOO, suite en bas
Application.SendKeys " ALT + esc " 'raccourcis clavier "réduire"
X = Range("E45").Value
Y = Range("E11").Value
Z = Range("H17").Value
CheminDuFichier = Z & " - " & Y & " - " & X & " € " & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="C:\Users\" & Environ("username") & "\Desktop\" & CheminDuFichier, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, From:=1, To:=1, OpenAfterPublish:=False
With OutlookMail
.To = Range("E19").Value 'le destinataire
.Subject = " facture"
.Body = "Bonjour" & vbCr & "Veuillez trouver ci-joint mon offre de prix" & vbCr & " Cordialement " 'texte a rajouter"
.Attachments.Add "C:\Users\" & Environ("username") & "\Desktop\" & CheminDuFichier
.Display
'Application.SendKeys "%S" 'Pour l'instruction SendKeys, % signifie la touche Alt
'% permet donc d'appeler le menu Outlook
'S permet d'éxecuter Send (Envoyer)
Application.SendKeys "F9"
.Send
End With
Set OutlookApp = Nothing
Set OutlookMail = Nothing
nomUtilisateur = Application.UserName
Kill "C:\Users\" & nomUtilisateur & "\Desktop\" & CheminDuFichier
'pour fermer outlook :
'For Each Process In GetObject("winmgmts:").InstancesOf("Win32_process")
'If Process.Name = "OUTLOOK.EXE" Then Process.Terminate
'Next
End Sub
et à la suite de cette macro, évidemment la solution de YALOO donnée plus haut, qui , comme dab, me sauve des situations critiques
Function OutlookOuvert() As Boolean
Dim oOL As Object
On Error Resume Next
Set oOL = GetObject(, "Outlook.Application") 'si (, "Outlook.Application", vbhide ) pb active x, incompatible
On Error GoTo 0
OutlookOuvert = Not (oOL Is Nothing)
Set oOL = Nothing
End Function