1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| '----------------------------------------------------
'
' Il faut activer la référence : (dans Outils/Références)
' Microsoft CDO X.XX Library
' Microsoft Outlook X.XX Object Library
'
'----------------------------------------------------
Sub EmbeddedHTMLGraphicDemo()
' Outlook objects
Dim objApp As Outlook.Application
Dim l_Msg As MailItem
Dim colAttach As Outlook.Attachments
Dim l_Attach As Outlook.Attachment
Dim oSession As MAPI.Session
' CDO objects
Dim oMsg As MAPI.Message
Dim oAttachs As MAPI.Attachments
Dim oAttach As MAPI.Attachment
Dim colFields As MAPI.Fields
Dim oField As MAPI.Field
Dim strEntryID As String
Dim strHtml As String
'Appel de la fonction pour la crétion de l'image dans le répertoire c:\Temp
Image
Chemin_Fichier_en_PJ = Sheets("Destinataires").Range("cc1").Value
' create new Outlook MailItem
Set objApp = CreateObject("Outlook.Application")
Set l_Msg = objApp.CreateItem(olMailItem)
Set colAttach = l_Msg.Attachments
Set l_Attach = colAttach.Add("d:\Temp\test.gif")
l_Msg.Close olSave
strEntryID = l_Msg.EntryID
Set l_Msg = Nothing
Set colAttach = Nothing
Set l_Attach = Nothing
' initialize CDO session
On Error Resume Next
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, False
Set oMsg = oSession.GetMessage(strEntryID)
Set oAttachs = oMsg.Attachments
Set oAttach = oAttachs.Item(1)
Set colFields = oAttach.Fields
Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
Set oField = colFields.Add(&H3712001E, "myident")
oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
oMsg.Update
Set l_Msg = objApp.GetNamespace("MAPI").GetItemFromID(strEntryID)
strHtml = "Bonjour, <BR><BR>"
strHtml = strHtml & "Pouvez-vous me faire un retour concernant XXXXXXX ?"
strHtml = strHtml & "<BR><BR>"
strHtml = strHtml & "<IMG align=baseline border=0 hspace=0 src=cid:myident>"
strHtml = strHtml & "<BR><BR>" & _
"Cordialement," & "<BR><BR>"
strHtml = strHtml & "<B><font style='font-family: Arial ;font-size: 10pt ;' color=midnightblue>XXXXXXXXXX</Font></B>" & "<BR>"
strHtml = strHtml & "<font style='font-family: Arial ;font-size: 10pt ;' color=midnightblue>XXXXXXXXXXXXXXXX</Font>" & "<BR>"
strHtml = strHtml & "<font style='font-family: Arial ;font-size: 10pt ;' color=midnightblue>XXXXXXXXXXX</Font>" & "<BR>"
strHtml = strHtml & "<font style='font-fa"
Attachments.Add (Chemin_Fichier_en_PJ)
l_Msg.HtmlBody = strHtml
l_Msg.Close (olSave)
l_Msg.display
l_Msg.To = "toto@orange.fr"
l_Msg.Send
' clean up objects
Set oField = Nothing
Set colFields = Nothing
Set oMsg = Nothing
oSession.Logoff
Set oSession = Nothing
Set objApp = Nothing
Set l_Msg = Nothing
End Sub
Sub Image()
Dim Plage As Range
On Error Resume Next
MkDir "D:\Temp"
Set Plage = Sheets("Liste de Choix").Range("B1:C16")
Application.ScreenUpdating = False
Workbooks.Add: Plage.CopyPicture: ActiveSheet.Paste
With ActiveSheet.ChartObjects.Add(0, 0, Selection.Width, Selection.Height).Chart
.Paste
.Export "D:\Temp\Test.gif", "GIF"
End With
ActiveWorkbook.Close False
End Sub |
Partager