Public Sub TestMail() Dim oOoA As Outlook.Application Dim oOoItem As Outlook.MailItem Dim oOoRcp As Outlook.Recipient Dim aTemp() As Byte Dim ff As Integer Set oOoA = New Outlook.Application Set oOoItem = oOoA.CreateItem(olMailItem) With oOoItem ' Destinataire(s) Set oOoRcp = .Recipients.Add("toto@serveur.fr") oOoRcp.Type = olTo ' Sujet du mail .Subject = "Coucou Subject" ' Formattage du message préparé dans un fichier RTF ff = FreeFile Open ActiveWorkbook.Path & "\Bonjour.rtf" For Binary Access Read As #ff ReDim aTemp(0 To LOF(ff) - 1) Get #ff, , aTemp Close #ff .BodyFormat = olFormatRichText .RTFBody = aTemp ' Fichier joint .Attachments.Add ActiveWorkbook.Path & "\Fichier test.pdf", OlAttachmentType.olEmbeddeditem .Send End With End Sub
Set oBjMail = ObjOutlook.GetOpenFilename("C:\Users\Anthony\Desktop\CXN n82 + Fiche Adhésion 2014.msg")
Sub Send_Mail_Outlook()
'Il faut activer la référence "Microsoft Outlook Library" Avant de lancer cette macro,
'Dans l 'éditeur VBA: Faire Menu / Tools / Reference / Cocher "Microsoft Outlook Library"
Dim i As Integer
'For i = 1 To 5000 Step 1
Set oBjMail = GetObject(, "Outlook.Application")
If oBjMail Is Nothing Then Err.Raise ERR_OUTLOOK_NOT_OPEN
Set Eml = oBjMail.CreateItemFromTemplate("C:\Users\Anthony\Desktop\CXN n82 + Fiche Adhésion 2014.msg")
With Eml
.To = Range("A" & i).Value ' le destinataire
.Send ' Ici on peut mettre '.Send' pour l'envoyer sans vérification
End With
'Next
End Sub
? maVariablepour qu'elle s'inscrive dans la fenêtre.
Sub Send_Mail_Outlook()
'Il faut activer la référence "Microsoft Outlook Library" Avant de lancer cette macro,
'Dans l 'éditeur VBA: Faire Menu / Tools / Reference / Cocher "Microsoft Outlook Library"
Dim i, n As Integer
Dim Destinataire As String
Dim Eml As MailItem
'Calcul du nombre de mails
n = 0
For Each Cell In Sheets(1).Columns(1).Cells
If IsEmpty(Cell) = False Then n = n + 1
Next Cell
For i = 1 To n Step 1
Set oBjMail = GetObject(, "Outlook.Application")
If oBjMail Is Nothing Then Err.Raise ERR_OUTLOOK_NOT_OPEN
Set Eml = oBjMail.CreateItemFromTemplate("C:\Users\Anthony\Desktop\CXN n82 + Fiche Adhésion 2014.msg")
With Eml
.To = Range("A" & i).Value ' le destinataire
.Send ' Ici on peut mettre '.Send' pour l'envoyer sans vérification
End With
Application.StatusBar = "Merci de patienter"
Application.Wait Now + TimeValue("00:00:10")
Application.StatusBar = False
Next
End Sub
' Ces lignes n'ont rien à faire DANS la bouclePS : "Cell" ressemble trop à un mot clé du langage : attention aux erreurs de compilation difficiles à trouver en pareil cas.
Set oBjMail = GetObject(, "Outlook.Application")
If oBjMail Is Nothing Then
Err.Raise ERR_OUTLOOK_NOT_OPEN
Else
For Each maCell In Sheets(1).Columns(1).Cells
If IsEmpty(maCell) = True Then Exit For
Set Eml = oBjMail.CreateItemFromTemplate(" ...
Eml.To = maCell.Value ' le destinataire
Eml.Send
' ici la tempo
Next maCell
End If
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.