Envoi mail 2003-2007 : référence absente

juju_69

XLDnaute Occasionnel
Bonjour,

J'ai plusieurs fichiers qui gèrent l'envoi de mails en automatique via excel. Ces fichiers peuvent être utiliser à la fois par des utilisateurs d'excel 2003 ou de 2007. Le souci que j'ai c'est que le dernier qui enregistre le fichier à "raison".

Au niveau de vba dans outils \ références, il est nécessaire que soit coché "Microsoft outlook XX object library". Si j'ai fait le fichier en 2007, j'aurai donc coché "Microsoft outlook 12 object library"", si un utilisateur ouvre le fichier avec excel2003, la référence sera indiqué comme absente et il faudra cocher "Microsoft outlook 11 object library" pour que cela fonctionne (idem à l'inverse).

Voici le code utilisé :

Sub EnvoiMail_Outlook()
Dim ol As New Outlook.Application
Dim olmail As MailItem
Dim CurrFile As String
Set ol = New Outlook.Application
Set olmail = ol.CreateItem(olmailItem)
With olmail
.To = "desti@free.fr"
.Subject = ActiveWorkbook.FullName
.Body = "corps du texte"
.Attachments.Add "C:\PGI\Résultats.xls"
.Display
End With
End Sub

J'ai bien lancé une recherche(et des sujets sur les mails il y en a bcp) mais je n'ai rien trouvé sur ce sujet...

Merci pour votre aide
 

MichelXld

XLDnaute Barbatruc
Re : Envoi mail 2003-2007 : référence absente

bonsoir,


Une solution consiste à créer une instance Late Binding :

Code:
Dim ol As Object
Dim olmail As Object
Dim CurrFile As Object

Set ol = CreateObject("Outlook.Application")
Set olmail = ol.CreateItem(0)

With olmail
    .To = "[EMAIL="desti@free.fr"]desti@free.fr[/EMAIL]"
    .Subject = ActiveWorkbook.FullName
    .Body = "corps du texte"
    .Attachments.Add "C:\PGI\Résultats.xls"
    .Display
End With


bonne soirée
michel
Microsoft Excel MVP
 

Roland_M

XLDnaute Barbatruc
Re : Envoi mail 2003-2007 : référence absente

bonjour

une méthode simple et efficace qui ne tient pas compte de 2003 ou 2007

Code:
'                                    CDO envoi messagerie directement                                  .
'                 CDO=(Collaboration Data Object) interface accédant à la couche MAPI                  .
Public Sub EnvoiMailCDO(TestEnvoiOk As Boolean) 'TestEnvoiOk pour test enn retour appel
On Error Resume Next
Dim cMail As New CDO.Message
If Err Then 'test si Réfce "Microsoft CDO for..."
   m$ = "CDO n'est pas installé !" & vbLf & _
   "Vous devez cocher(du côté VB) la référence suivante:" & vbLf & _
   "Microsoft CDO for..." & vbLf & _
   "probablement: Microsoft CDO for Windows 2000 Library"
   MsgBox m$, vbCritical, "Erreur référence"
   On Error GoTo 0: Err.Clear
   TestEnvoiOk = False: Exit Sub
End If
Application.ScreenUpdating = False
'envoi direct Email sur messagerie
'init var utiles /création Fichier '<<<
On Error GoTo ErreurMessagerie
With cMail
 .From = EmailAdresExpediteur '<<<
 .To = EmailAdresDestinataire '<<<
 .Subject = EmailSujet '<<<
 .TextBody = EmailMessage '<<<
 .AddAttachment (EmailCheminFichier) '<<<
 .Send
End With
'
On Error GoTo 0: Err.Clear
TestEnvoiOk = True
Application.ScreenUpdating = True
Exit Sub
ErreurMessagerie: 'routine erreur
Msg$ = "Erreur " & Err.Source & "  No " & Err.Number & vbLf & vbLf & Err.Description & vbLf & vbLf & "Vérifiez si vous êtes bien connecté !?"
T$ = "Problème de connexion..."
MsgBox Msg$, vbCritical, T$, Err.HelpFile, Err.HelpContext
On Error GoTo 0: Err.Clear
TestEnvoiOk = False
Application.ScreenUpdating = True
End Sub
 

micky01

XLDnaute Occasionnel
Re : Envoi mail 2003-2007 : référence absente

Bonjour à tous,

bonsoir,


Une solution consiste à créer une instance Late Binding :

Code:
Dim ol As Object
Dim olmail As Object
Dim CurrFile As Object

Set ol = CreateObject("Outlook.Application")
Set olmail = ol.CreateItem(0)

With olmail
    .To = "[EMAIL="desti@free.fr"]desti@free.fr[/EMAIL]"
    .Subject = ActiveWorkbook.FullName
    .Body = "corps du texte"
    .Attachments.Add "C:\PGI\Résultats.xls"
    .Display
End With


bonne soirée
michel
Microsoft Excel MVP

ceci marche bien pour moi, j'aimerais juste savoir si il est possible de mettre un lien hypertexte dans le corps de texte? :confused:
Je pense bien que ca ne doit pas être compliqué mais bon :(

Merci de votre aide :p
 

MichelXld

XLDnaute Barbatruc
Re : Envoi mail 2003-2007 : référence absente

bonjour

Remplace Body par HTMLBody :

Code:
Dim ol As Object
Dim olmail As Object
 
Set ol = CreateObject("Outlook.Application")
Set olmail = ol.CreateItem(0)
 
With olmail
    .To = "[EMAIL="forum@xld.fr"]forum@xld.fr[/EMAIL]"
    .Subject = "Le titre du message"
    '\\FRRCHNT1 nom du serveur hebergeant le fichier lié
    .HTMLBody = "<BODY><A href='http://www.excel-downloads.com/'>Mon lien</A></BODY>"
    .Display
End With



bonne soirée
michel
Microsoft Excel MVP
 

Discussions similaires

Réponses
3
Affichages
708

Statistiques des forums

Discussions
312 300
Messages
2 087 020
Membres
103 435
dernier inscrit
azizou31