Insertion Signature

Bonjour,

Je souhaite générer un mail avec du texte, une image (au centre) et ma signature (à la fin).

J'utilise le code ci-dessous :

Sub createMailWithSignature()

Dim objMsg As Object
Dim OutMail As Object
Dim wb As Workbook
Dim wDoc As Object
Set wb = ActiveWorkbook

Set objMsg = CreateObject("Outlook.Application")
Set OutMail = objMsg.CreateItem(olMailItem)
Set wDoc = OutMail.GetInspector.WordEditor

    With OutMail
        .Display
        .To = "xxx@xxx.com"
        .CC = "xxx@xxx.com"
        .Subject = "SUJET"

        wb.Sheets(1).Range("A2:J9").CopyPicture
        Set Rng = wDoc.Content

        Rng.Application.Selection.Paste

        If Not (Rng Is Nothing) Then
        Rng.InsertBefore ("Bonjour" & vbCr & vbCr & "blablabla" & vbCr & vbCr)
        Rng.InsertAfter (vbCr & vbCr & "blablabla" & vbCr & vbCr & "Cordialement," & vbCr)
        End If

    End With
    Set Rng = Nothing
    InsertSignature OutMail, "RT"
    Application.CutCopyMode = False

End Sub

Et la fonction suivante :

Sub InsertSignature(OutMail As Object, SignatureName As String)

    Dim wd As Object, obSelection As Object
    Dim enviro, strSigFilePath
    Const wdStory = 6
    Const wdParagraph = 4
    Const wdGoToBookmark = -1
    Const wdExtend = 0
    Const wdSortByName = 0
    enviro = CStr(Environ("appdata"))
    strSigFilePath = enviro & "\Microsoft\Signatures\"

    Set wd = OutMail.GetInspector.WordEditor
    Set obSelection = wd.Application.Selection
    obSelection.Move wdStory, -1

    obSelection.Move wdParagraph, 1
    obSelection.Paragraphs.Add
    obSelection.Move wdParagraph, 1

    Dim oBookmark
    Set oBookmark = obSelection.Bookmarks.Add("_Sig", obSelection.Range)

    If Dir(strSigFilePath & SignatureName & ".htm", vbNormal) <> "" Then
        obSelection.InsertFile Filename:=strSigFilePath & SignatureName & ".htm", Range:="", ConfirmConversions:= _
                               False, Link:=False, Attachment:=False

        obSelection.GoTo What:=wdGoToBookmark, Name:="_Sig"

        obSelection.EndKey Unit:=wdStory, Extend:=wdExtend
        With wd.Bookmarks
            .Add Range:=obSelection.Range, Name:="_MailAutoSig"
            .DefaultSorting = wdSortByName
            .ShowHidden = False
        End With

        obSelection.Move wdStory, -1
    End If
End Sub

Le code fonctionne mais le soucis c'est qu'il insère la signature après le "Bonjour" au lieu de mettre à la fin

Avez-vous une solution ?

Merci

Salut Erhan,

Un simple Call InsertSignature ne fonctionne pas ?

Sinon, regarde ici, une autre manière de mettre une signature

Bonne soirée,

Baboutz

Bonjour Erhan, bonjour Baboutz

Pour insérer ma signature, je faisais très simplement :

With OutMail
    .htmlbody = "Bla bla " & .htmlbody
    ' ... le reste des options
    .display
end with
Rechercher des sujets similaires à "insertion signature"