Comment éviter l'envoi de mail si cellule vide
z
Bonsoir à tous
Encore Bonne fête de l'ascension à tous.
J'ai 2 code :
le 1er ci-dessous me permet d'envoyer des mails à des clients.
Sub Mail_PIECES_JOINTES()
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010.
' This example sends the last saved version of the Activeworkbook object .
Dim OutApp As Object
Dim OutMail As Object
Dim texte As String
Dim I As String
Dim Nomfic As String, spath As String, Nomfic1 As String, spath1 As String, spath2 As String, nomfic2 As String, spath3 As String, nomfic3 As String
spath = Environ("USERPROFILE")
spath1 = Environ("USERPROFILE")
spath2 = Environ("USERPROFILE")
spath3 = Environ("USERPROFILE")
spath = spath & "\bureau\SGIIOC\"
spath1 = spath1 & "\bureau\SGIIOC\"
spath2 = spath2 & "\bureau\SGIIOC\"
spath3 = spath3 & "\bureau\SGIIOC\"
Nomfic = Sheets("parametre").Range("A107").Value
Nomfic1 = Sheets("parametre").Range("A108").Value
nomfic2 = Sheets("parametre").Range("A109").Value
nomfic3 = Sheets("parametre").Range("A1010").Value
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
I = Range("B29").Value
texte = texte & Range("B39").Value & " le, " & Range("E17").Value & vbCrLf & vbCrLf
texte = texte & "A" & vbCrLf
texte = texte & Range("AF3").Value & vbCrLf
texte = texte & Range("B26").Value & vbCrLf
texte = texte & Range("B27").Value & vbCrLf & vbCrLf & vbCrLf
On Error Resume Next
With OutMail
.To = Range("B29").Value
.CC = ""
.BCC = ""
.Subject = "Bienvenue dans"
.Body = texte
.Attachments.Add spath & Nomfic
.Attachments.Add spath1 & Nomfic1
.Attachments.Add spath2 & nomfic2
.Attachments.Add spath3 & nomfic3
.Send
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Je passe par le 2è code pour appeler la macro envoi mail.
Je souhaite que lorsque la cellule B26 est vide ou si y'a NEANT, qu'il n'est pas d'envoi même si la macro est appelée.
Sub IMPRESSION_FEUILLES()
'Déclaration des variables
Dim valeur_donne_E20 As String
'Sélection de la valeur de !DONNE E20 et mise en variable
Sheets("DONNE").Select
Range("E20").Select
valeur_donne_E20 = ActiveCell.Value
'---------------------------------
'Vérification des conditions 1 à 72
'---------------------------------
'test de la condition 1 - 1 (PS PUBLIC sans manquant)
If valeur_donne_E20 = "1" Then
Sheets("PS").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("FRGLE").Select
ActiveWindow.SelectedSheets.PrintOut From:=2, To:=2, Copies:=1, Collate _
:=True
Sheets("SPECI").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("DCHQ").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("SOLDE").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True
'Sheets("MONETIQUE").Select
'ActiveWindow.SelectedSheets.PrintOut From:=1, To:=2, Copies:=1, Collate _
':=True
Sheets("CLISTE").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("DONNE").Select
Range("B4").Select
Call Mail_PIECES_JOINTES
'test de la condition 1 - 2 (PS PUBLIC avec VP)
ElseIf valeur_donne_E20 = "2" Then
Sheets("PS").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("FRGLE").Select
ActiveWindow.SelectedSheets.PrintOut From:=2, To:=2, Copies:=1, Collate _
:=True
Sheets("SPECI").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("DCHQ").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("VP").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("SOLDE").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=3, Copies:=1, Collate _
:=True
'Sheets("MON").Select
'ActiveWindow.SelectedSheets.PrintOut From:=1, To:=2, Copies:=1, Collate _
':=True
Sheets("CLISTE").Select
ActiveWindow.SelectedSheets.PrintOut From:=1, To:=1, Copies:=1, Collate _
:=True
Sheets("DONNE").Select
Range("B4").Select
Call Mail_PIECES_JOINTES
Else: MsgBox ("Rien à imprimer")
'Fin de la vérification des conditions
End If
End Sub
Merci
Re
Essaie de placer le code suivant juste avant chaque Call Mail_PIECES_JOINTES
If Range("B26") = "" Or Range("B26") = "NEANT" Then Exit Sub
Cordialement
z
Salut yvouille
C'est propre.
Merci infiniment pour tes solutions magiques.
Peace