Insérer signature Outlook à partir macro excel

btellier

XLDnaute Junior
Bonjour,
le code ci-dessous me génère un mail qui s'affiche directement dans outlook. Tout fonctionne excepté la signature qui ne s'affiche pas, or elle est créée et paramétrée dans Outlook à la base.

J'imagine que je dois insérer un bout de code pour la générer automatiquement avec le corps du message.

Toute aide serait très appréciable et merci par avance.


Sub SendMail_Relance()
Dim ol As New Outlook.Application
Dim olmail As MailItem
Dim CurrFile As String
Dim Chemin$, Client$, Fichier$

Set ol = New Outlook.Application
Set olmail = ol.CreateItem(olMailItem)
With olmail
.To = Range("a13").Value
.Subject = Range("a10").Value
.Body = ActiveSheet.Range("E19") & ActiveSheet.Range("L19") & vbNewLine & _
"" & vbNewLine & vbNewLine & _
ActiveSheet.Range("A11") & "," & vbNewLine & _
vbNewLine & _
"Nous vous prions de trouver ci-dessous le relevé de votre compte ..." & vbNewLine & _
"Cordialement," & vbNewLine & _
vbNewLine & _
"Comptabilité Clients" & vbCrLf & _
""
.Display '.Send
End With
End Sub
 

Hervé

XLDnaute Barbatruc
Re : Insérer signature Outlook à partir macro excel

salut


normalement ta signature se trouve ici :

C:\Documents and Settings\(tonusernam)\Application Data\Microsoft\Signatures

sous la forme sois d'un fichier TXT, HTML ou RTF, il te suffit dans ta macro de la récup et de l'ajouter au corps de ton mail :


Code:
.Body = ActiveSheet.Range("E19") & ActiveSheet.Range("L19") & vbNewLine & _
"" & vbNewLine & vbNewLine & _
ActiveSheet.Range("A11") & "," & vbNewLine & _
vbNewLine & _
"Nous vous prions de trouver ci-dessous le relevé de votre compte ..." & vbNewLine & _
"Cordialement," & vbNewLine & _
vbNewLine & _
"Comptabilité Clients" & vbCrLf & signature

salut
 

Hervé

XLDnaute Barbatruc
Re : Insérer signature Outlook à partir macro excel

re

Allez, je suis sympa aujourd'hui (hein ??? quoi ??? qui à dit comme toujours ??? m'insultez pas svp:D)


un code pour recup le txt de ta signature :

Code:
Sub test()
MsgBox recuptxt("chemin d'acces\nom.txt")
End Sub
 
Public Function recuptxt(chemin As String)
Dim fso As Object
Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(chemin).OpenAsTextStream(1, -2)
    recuptxt = ts.readall
    ts.Close
End Function

a plus
 

btellier

XLDnaute Junior
Re : Insérer signature Outlook à partir macro excel

Merci Hervé pour cette réponse.
Le bout de code pour récuperer le txt de la signature fonctionne. Etant débutant, je colle bêtement le txt à la suite de ma macro (partie en gras) mais cela ne fonctionne pas, j'oublie surement un caractère...


vbNewLine & _
"Comptabilité Clients" & vbCrLf & _
vbNewLine & _
<img src="file:///C:\Documents and Settings\Administrateur\Bureau\LOGO MT.gif"><br> & vbCrLf & _
<font face="Tahoma" size="2"font color="#808080"><b>Benoit Tellier</b></font><br>
<font face="Tahoma" size="2"font color="#808080">tél: 01 49 92 88 17</b></font><br>
<font face="Tahoma" size="2"font color="#808080">fax: 01 49 92 17 25</b></font><br>
<font face="Tahoma" size="2"font color="#808080"> Route Principale du Port</b></font><br>
<font face="Tahoma" size="2"font color="#808080">92230 Clichy</b></font><br>
<font face="Tahoma" size="2"font color="#FFA500" a href="http://file:///www.magellan.com/">www.magellan-transit.com</a>

""
.Display '.
End With
End Sub
 

Hervé

XLDnaute Barbatruc
Re : Insérer signature Outlook à partir macro excel

salut btellier

essaye comme ceci, pense à changer le chemin d'acces et le nom de ton txt (en rouge) :

Code:
Public Function recuptxt(chemin As String) 
Dim fso As Object
Dim ts As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(chemin).OpenAsTextStream(1, -2)
recuptxt = ts.readall
    ts.Close
End Function
Code:
Sub SendMail_Relance()
Dim ol As New Outlook.Application
   Dim olmail As MailItem
   Dim CurrFile As String
   Dim Chemin$, Client$, Fichier$

   Set ol = New Outlook.Application
   Set olmail = ol.CreateItem(olMailItem)
   With olmail
      .To = Range("a13").Value
      .Subject = Range("a10").Value
      .Body = ActiveSheet.Range("E19") & ActiveSheet.Range("L19") & vbNewLine & _
              "" & vbNewLine & vbNewLine & _
              ActiveSheet.Range("A11") & "," & vbNewLine & _
              vbNewLine & _
              "Nous vous prions de trouver ci-dessous le relevé de votre compte  ..." & vbNewLine & _
              "Cordialement," & vbNewLine & _
              vbNewLine & _
              "Comptabilité Clients" & vbCrLf & _
              ""&recuptxt("
[COLOR=Red]C:\Documents and Settings\(tonusernam)\Application Data\Microsoft\Signatures\tonfichier.txt[/COLOR]")
    .Display '.Send
   End With
End Sub

salut
 

btellier

XLDnaute Junior
Re : Insérer signature Outlook à partir macro excel

Merci Hervé.
Cette fois ci-c'est bon, ta macro me récupère bien le texte et me le colle au corps du message mais j'ai encore un souci. J'aimerai qu'elle me colle le format HTML. J'ai changé l’extension de mon fichier signature (en remplaçant .txt par .html) mais la macro continue à coller la signature en format txt. Je ne sais as si j'ai été clair et encore une fois désolé pour ces nombreux allers/retours.

Salut
 

Discussions similaires

Réponses
3
Affichages
707

Statistiques des forums

Discussions
312 276
Messages
2 086 714
Membres
103 378
dernier inscrit
phdrouart