Erreur lors d'une exécution de macro

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.

Bonjour,

Faut il paramétrer Excel avant pour que celui-ci communique avec Outlook ?

Cordialement.

Bonsoir,

Vérifie que la bibliothèque Outlook soit activée dans les références.

Cordialement.

Bonjour,

Voici ci joint les references. Pourriez vous me dire si cela est bon ?

Cordialement.

pb email

bonjour,

1) comme tu utilises du "late binding", pas besoin de mettre la référence à outlook si tu remplaces olformatHTML par sa valeur (2)

2) ajoute . value à cells(m,1) qui identifie le destinataire.

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).value
        .Subject = Range("Objet_Mail").Value
        .body = Range("Text_Mail").Value
        .BodyFormat = 2 'olhmtlformat
        .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

Vous êtes super

Sa marche nickel

Ecore merci.

Rechercher des sujets similaires à "erreur lors execution macro"