Bonjour à tous,
J'ai un petit souci que je n'arrive pas a comprendre.
J'ai créée ce code ci-dessous avec Microsoft Excel 2010.
J'ai changé de pc pour le tester sur un autre ordinateur avec Micrsoft 2007 et un autre avec 2013.
Le problème c'est que sur Microsoft 2010 la macro fonctionne trés bien, mais dés que je passe sur 2007 ou 2013 j'ai un message d'erreur :
Erreur d'exécution '-2147417851 (800 10 105)':
La méthode 'To' de l'objet '_MailItem' à échoué
Voici le code :
Sub Envoi_Mail()
Dim Rep As Integer
Rep = MsgBox("Voulez-vous vraiment envoyer les Email ?", vbYesNo + vbQuestion, "mDF XLpages.com")
If Rep = vbYes Then
Sheets("Base Donnée Client").Select
Dim i, j, nbcells As Integer
i = 2
j = 1
nbcells = WorksheetFunction.CountA(Columns(3))
'col 3 => col 1
'7 en 2
While i <= nbcells
If Cells(i, 7).Value <> "" Then
Sheets("DataMail").Cells(j, 1).Value = Cells(i, 7).Value
End If
If Cells(i, 7).Value <> "" Then
j = j + 1
End If
i = i + 1
Wend
Sheets("DataMail").Select
Dim messagerie As Object
Dim Email As Object
Dim m, nbmail As Integer
Dim Nom_Fichier As String
m = 1
nbmail = WorksheetFunction.CountA(Columns(1))
Nom_Fichier = Application.GetOpenFilename()
If Nom_Fichier = "Faux" Then Exit Sub
While m <= nbmail
If Cells(m, 1).Value <> "" Then
Set messagerie = CreateObject("Outlook.Application")
Set Email = messagerie.CreateItem(0)
With Email
.To = Cells(m, 1)
.Subject = Range("Objet_Mail").Value
.body = Range("Text_Mail").Value
.BodyFormat = olFormatHTML
.Attachments.Add Nom_Fichier
.send
End With
End If
m = m + 1
Wend
Sheets("Email").Select
MsgBox "Mail Transmis", vbOKOnly + vbInformation, "mDF XLpages.com"
Else
MsgBox "Mail Non Transmis", vbOKOnly + vbInformation, "mDF XLpages.com"
End If
End Sub
Merci à vous de votre aide.
Cordialement.