[Excel - Visual] - Envoyer un mail outlook Express en visual Excel
2 réponses
mcog
Bonjour,
Lorsque j'envoie trop de texte dans le body (variable corps), le mail ne se
compose pas.
Si je diminue la variable corps, ca passe.
Voir code ci-dessous
Merci,
Olivier
Private Declare Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub mail()
Dim Destinataire As String
Dim Objet As String
Dim Corps As String
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
Pascal
Bonsoir, J'ai eu le même probléme résolu avec l'aide de JB et d'autres contributeurs de cette manière
Sub ole() Dim oApp As Word.Application, doc As Word.Document Sheets("Env").Select Range("B2").Select ' premier client Do While Not IsEmpty(ActiveCell) On Error Resume Next nf = ThisWorkbook.Path & "Corps_mail.doc" 'Choix du corps du mail et bien sur à adapter Set oApp = CreateObject("Word.Application") oApp.Visible = True Set doc = oApp.Documents.Open(nf) If Err <> 0 Then MsgBox "Le fichier publi.doc doit être dans " & ThisWorkbook.Path Exit Sub End If On Error GoTo 0 ' Annule la gestion d'erreur '-- Société = ActiveCell.Value 'ici B2 Email = ActiveCell.Offset(0, 8).Value Corps = doc.Content.Text 'Récupére le doc choisi plus haut pour l'insérer en corps de mail '-- nom_doc = ThisWorkbook.Path & "" & Société & ".doc" doc.SaveAs nom_doc oApp.Quit '------------------------ envoi par mail Dim olapp As Outlook.Application Dim Msg As MailItem Set olapp = New Outlook.Application Set Msg = olapp.CreateItem(olMailItem) Msg.To = Email Msg.Subject = Sujet Msg.Body = Corps Msg.Attachments.Add Source:="C:TotolToto_1doc" 'Insertion de la pièce jointe Msg.Send Set olapp = Nothing ActiveCell.Offset(1, 0).Select ' Client suivant Loop Set oApp = Nothing MsgBox "Message envoyé" End Sub
"mcog" a écrit dans le message de news: 460c0b3f$0$27408$
Bonjour,
Lorsque j'envoie trop de texte dans le body (variable corps), le mail ne se compose pas. Si je diminue la variable corps, ca passe. Voir code ci-dessous
Merci,
Olivier
Private Declare Function ShellExecute _ Lib "shell32.dll" _ Alias "ShellExecuteA" ( _ ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long
Sub mail()
Dim Destinataire As String Dim Objet As String Dim Corps As String
--- Antivirus avast! : message Entrant sain. Base de donnees virale (VPS) : 000728-2, 28/03/2007 Analyse le : 29/03/2007 21:41:32 avast! - copyright (c) 1988-2007 ALWIL Software. http://www.avast.com
--- Antivirus avast! : message Sortant sain. Base de donnees virale (VPS) : 000728-2, 28/03/2007 Analyse le : 29/03/2007 21:46:25 avast! - copyright (c) 1988-2007 ALWIL Software. http://www.avast.com
Bonsoir,
J'ai eu le même probléme résolu avec l'aide de JB et d'autres contributeurs
de cette manière
Sub ole()
Dim oApp As Word.Application, doc As Word.Document
Sheets("Env").Select
Range("B2").Select ' premier client
Do While Not IsEmpty(ActiveCell)
On Error Resume Next
nf = ThisWorkbook.Path & "Corps_mail.doc" 'Choix du corps du mail et
bien sur à adapter
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set doc = oApp.Documents.Open(nf)
If Err <> 0 Then
MsgBox "Le fichier publi.doc doit être dans " & ThisWorkbook.Path
Exit Sub
End If
On Error GoTo 0 ' Annule la gestion d'erreur
'--
Société = ActiveCell.Value 'ici B2
Email = ActiveCell.Offset(0, 8).Value
Corps = doc.Content.Text 'Récupére le doc choisi plus haut pour
l'insérer en corps de mail
'--
nom_doc = ThisWorkbook.Path & "" & Société & ".doc"
doc.SaveAs nom_doc
oApp.Quit
'------------------------ envoi par mail
Dim olapp As Outlook.Application
Dim Msg As MailItem
Set olapp = New Outlook.Application
Set Msg = olapp.CreateItem(olMailItem)
Msg.To = Email
Msg.Subject = Sujet
Msg.Body = Corps
Msg.Attachments.Add Source:="C:TotolToto_1doc" 'Insertion de la pièce
jointe
Msg.Send
Set olapp = Nothing
ActiveCell.Offset(1, 0).Select ' Client suivant
Loop
Set oApp = Nothing
MsgBox "Message envoyé"
End Sub
"mcog" <mcog2NO-SPAM@wanadoo.frNO-SPAM> a écrit dans le message de news:
460c0b3f$0$27408$ba4acef3@news.orange.fr...
Bonjour,
Lorsque j'envoie trop de texte dans le body (variable corps), le mail ne
se compose pas.
Si je diminue la variable corps, ca passe.
Voir code ci-dessous
Merci,
Olivier
Private Declare Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub mail()
Dim Destinataire As String
Dim Objet As String
Dim Corps As String
Bonsoir, J'ai eu le même probléme résolu avec l'aide de JB et d'autres contributeurs de cette manière
Sub ole() Dim oApp As Word.Application, doc As Word.Document Sheets("Env").Select Range("B2").Select ' premier client Do While Not IsEmpty(ActiveCell) On Error Resume Next nf = ThisWorkbook.Path & "Corps_mail.doc" 'Choix du corps du mail et bien sur à adapter Set oApp = CreateObject("Word.Application") oApp.Visible = True Set doc = oApp.Documents.Open(nf) If Err <> 0 Then MsgBox "Le fichier publi.doc doit être dans " & ThisWorkbook.Path Exit Sub End If On Error GoTo 0 ' Annule la gestion d'erreur '-- Société = ActiveCell.Value 'ici B2 Email = ActiveCell.Offset(0, 8).Value Corps = doc.Content.Text 'Récupére le doc choisi plus haut pour l'insérer en corps de mail '-- nom_doc = ThisWorkbook.Path & "" & Société & ".doc" doc.SaveAs nom_doc oApp.Quit '------------------------ envoi par mail Dim olapp As Outlook.Application Dim Msg As MailItem Set olapp = New Outlook.Application Set Msg = olapp.CreateItem(olMailItem) Msg.To = Email Msg.Subject = Sujet Msg.Body = Corps Msg.Attachments.Add Source:="C:TotolToto_1doc" 'Insertion de la pièce jointe Msg.Send Set olapp = Nothing ActiveCell.Offset(1, 0).Select ' Client suivant Loop Set oApp = Nothing MsgBox "Message envoyé" End Sub
"mcog" a écrit dans le message de news: 460c0b3f$0$27408$
Bonjour,
Lorsque j'envoie trop de texte dans le body (variable corps), le mail ne se compose pas. Si je diminue la variable corps, ca passe. Voir code ci-dessous
Merci,
Olivier
Private Declare Function ShellExecute _ Lib "shell32.dll" _ Alias "ShellExecuteA" ( _ ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long
Sub mail()
Dim Destinataire As String Dim Objet As String Dim Corps As String
--- Antivirus avast! : message Entrant sain. Base de donnees virale (VPS) : 000728-2, 28/03/2007 Analyse le : 29/03/2007 21:41:32 avast! - copyright (c) 1988-2007 ALWIL Software. http://www.avast.com
--- Antivirus avast! : message Sortant sain. Base de donnees virale (VPS) : 000728-2, 28/03/2007 Analyse le : 29/03/2007 21:46:25 avast! - copyright (c) 1988-2007 ALWIL Software. http://www.avast.com
mcog
Bonsoir, J'ai eu le même probléme résolu avec l'aide de JB et d'autres contributeurs de cette manière
Sub ole() Dim oApp As Word.Application, doc As Word.Document Sheets("Env").Select Range("B2").Select ' premier client Do While Not IsEmpty(ActiveCell) On Error Resume Next nf = ThisWorkbook.Path & "Corps_mail.doc" 'Choix du corps du mail et bien sur à adapter Set oApp = CreateObject("Word.Application") oApp.Visible = True Set doc = oApp.Documents.Open(nf) If Err <> 0 Then MsgBox "Le fichier publi.doc doit être dans " & ThisWorkbook.Path Exit Sub End If On Error GoTo 0 ' Annule la gestion d'erreur '-- Société = ActiveCell.Value 'ici B2 Email = ActiveCell.Offset(0, 8).Value Corps = doc.Content.Text 'Récupére le doc choisi plus haut pour l'insérer en corps de mail '-- nom_doc = ThisWorkbook.Path & "" & Société & ".doc" doc.SaveAs nom_doc oApp.Quit '------------------------ envoi par mail Dim olapp As Outlook.Application Dim Msg As MailItem Set olapp = New Outlook.Application Set Msg = olapp.CreateItem(olMailItem) Msg.To = Email Msg.Subject = Sujet Msg.Body = Corps Msg.Attachments.Add Source:="C:TotolToto_1doc" 'Insertion de la pièce jointe Msg.Send Set olapp = Nothing ActiveCell.Offset(1, 0).Select ' Client suivant Loop Set oApp = Nothing MsgBox "Message envoyé" End Sub
"mcog" a écrit dans le message de news: 460c0b3f$0$27408$
Bonjour,
Lorsque j'envoie trop de texte dans le body (variable corps), le mail ne se compose pas. Si je diminue la variable corps, ca passe. Voir code ci-dessous
Merci,
Olivier
Private Declare Function ShellExecute _ Lib "shell32.dll" _ Alias "ShellExecuteA" ( _ ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long
Sub mail()
Dim Destinataire As String Dim Objet As String Dim Corps As String
Ca marche pas mal, mais ca fait sauter tous les retours chariots, malgrés qu'il y en ai dans le fichier modele...
Combine ?
Merci,
Olivier
Bonsoir,
J'ai eu le même probléme résolu avec l'aide de JB et d'autres
contributeurs de cette manière
Sub ole()
Dim oApp As Word.Application, doc As Word.Document
Sheets("Env").Select
Range("B2").Select ' premier client
Do While Not IsEmpty(ActiveCell)
On Error Resume Next
nf = ThisWorkbook.Path & "Corps_mail.doc" 'Choix du corps du mail et
bien sur à adapter
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
Set doc = oApp.Documents.Open(nf)
If Err <> 0 Then
MsgBox "Le fichier publi.doc doit être dans " & ThisWorkbook.Path
Exit Sub
End If
On Error GoTo 0 ' Annule la gestion d'erreur
'--
Société = ActiveCell.Value 'ici B2
Email = ActiveCell.Offset(0, 8).Value
Corps = doc.Content.Text 'Récupére le doc choisi plus haut pour
l'insérer en corps de mail
'--
nom_doc = ThisWorkbook.Path & "" & Société & ".doc"
doc.SaveAs nom_doc
oApp.Quit
'------------------------ envoi par mail
Dim olapp As Outlook.Application
Dim Msg As MailItem
Set olapp = New Outlook.Application
Set Msg = olapp.CreateItem(olMailItem)
Msg.To = Email
Msg.Subject = Sujet
Msg.Body = Corps
Msg.Attachments.Add Source:="C:TotolToto_1doc" 'Insertion de la pièce
jointe
Msg.Send
Set olapp = Nothing
ActiveCell.Offset(1, 0).Select ' Client suivant
Loop
Set oApp = Nothing
MsgBox "Message envoyé"
End Sub
"mcog" <mcog2NO-SPAM@wanadoo.frNO-SPAM> a écrit dans le message de news:
460c0b3f$0$27408$ba4acef3@news.orange.fr...
Bonjour,
Lorsque j'envoie trop de texte dans le body (variable corps), le mail ne
se compose pas.
Si je diminue la variable corps, ca passe.
Voir code ci-dessous
Merci,
Olivier
Private Declare Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA" ( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Sub mail()
Dim Destinataire As String
Dim Objet As String
Dim Corps As String
Bonsoir, J'ai eu le même probléme résolu avec l'aide de JB et d'autres contributeurs de cette manière
Sub ole() Dim oApp As Word.Application, doc As Word.Document Sheets("Env").Select Range("B2").Select ' premier client Do While Not IsEmpty(ActiveCell) On Error Resume Next nf = ThisWorkbook.Path & "Corps_mail.doc" 'Choix du corps du mail et bien sur à adapter Set oApp = CreateObject("Word.Application") oApp.Visible = True Set doc = oApp.Documents.Open(nf) If Err <> 0 Then MsgBox "Le fichier publi.doc doit être dans " & ThisWorkbook.Path Exit Sub End If On Error GoTo 0 ' Annule la gestion d'erreur '-- Société = ActiveCell.Value 'ici B2 Email = ActiveCell.Offset(0, 8).Value Corps = doc.Content.Text 'Récupére le doc choisi plus haut pour l'insérer en corps de mail '-- nom_doc = ThisWorkbook.Path & "" & Société & ".doc" doc.SaveAs nom_doc oApp.Quit '------------------------ envoi par mail Dim olapp As Outlook.Application Dim Msg As MailItem Set olapp = New Outlook.Application Set Msg = olapp.CreateItem(olMailItem) Msg.To = Email Msg.Subject = Sujet Msg.Body = Corps Msg.Attachments.Add Source:="C:TotolToto_1doc" 'Insertion de la pièce jointe Msg.Send Set olapp = Nothing ActiveCell.Offset(1, 0).Select ' Client suivant Loop Set oApp = Nothing MsgBox "Message envoyé" End Sub
"mcog" a écrit dans le message de news: 460c0b3f$0$27408$
Bonjour,
Lorsque j'envoie trop de texte dans le body (variable corps), le mail ne se compose pas. Si je diminue la variable corps, ca passe. Voir code ci-dessous
Merci,
Olivier
Private Declare Function ShellExecute _ Lib "shell32.dll" _ Alias "ShellExecuteA" ( _ ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long
Sub mail()
Dim Destinataire As String Dim Objet As String Dim Corps As String