彰化一整天的論壇

 找回密碼
 立即註冊
查看: 605|回復: 0

【轉貼】Excel寄email內崁圖片使用outlook

[複製鏈接]
發表於 2018-5-5 18:37:33 | 顯示全部樓層 |閱讀模式
Excel-VBA : Send Mail with Embedded Image in message body From MS Outlook using Excel.
  1. Sub sumit()
  2. Dim mainWB As Workbook
  3. Dim SendID
  4. Dim CCID
  5. Dim Subject
  6. Dim Body
  7. Dim olMail As MailItem

  8. Set otlApp = CreateObject("Outlook.Application")
  9. Set olMail = otlApp.CreateItem(olMailItem)
  10. Set Doc = olMail.GetInspector.WordEditor
  11. 'Dim colAttach As Outlook.Attachments
  12. Dim oAttach As Outlook.Attachment

  13. Set mainWB = ActiveWorkbook

  14. SendID = mainWB.Sheets("Mail").Range("B1").Value
  15. CCID = mainWB.Sheets("Mail").Range("B2").Value
  16. Subject = mainWB.Sheets("Mail").Range("B3").Value
  17. Body = mainWB.Sheets("Mail").Range("B4").Value
  18. With olMail
  19.     .To = SendID
  20.     If CCID <> "" Then
  21.       .CC = CCID
  22.     End If
  23.     .Subject = Subject
  24.     'add the image in hidden manner, position at 0 will make it hidden
  25.     .Attachments.Add "C:\Users\Sumit Jain\Pictures\11\city.jpg", olByValue, 0

  26.     'Now add it to the Html body using image name
  27.     'change the src property to 'cid:your image filename'
  28.     'it will be changed to the correct cid when its sent.
  29.     .HTMLBody = .HTMLBody & "<br><B>Embedded Image:</B><br>" _
  30.                 & "<img src='cid:city.jpg'" & "width='500' height='200'><br>" _
  31.                 & "<br>Best Regards, <br>Sumit</font></span>"
  32.     .Display
  33.     .Send
  34. End With

  35. MsgBox ("you Mail has been sent to " & SendID)

  36. End Sub
複製代碼
文章來源: https://excel-macro.tutorialhori ... utlook-using-excel/
回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

 ㄚ母滴雞湯
 員林香純滴雞精

Archiver|手機版|小黑屋|彰化一整天的論壇(Excel,Office)  |网站地图

GMT+8, 2019-11-15 03:25 , Processed in 0.153761 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表