简体   繁体   English

将电子邮件从 Outlook 导出到 Excel 包括图像

[英]Exporting emails from outlook to Excel Including images

I am currently working on my project which is to export emails from Outlook to my Excel file.我目前正在处理我的项目,即将电子邮件从 Outlook 导出到我的 Excel 文件。

My current code is only exporting texts and not images.我当前的代码仅导出文本而不是图像。 Some of my emails have a snipped images (.png/.jpg).我的一些电子邮件有截图 (.png/.jpg)。

Is there a fix to this?有没有办法解决这个问题?

Here's my current code on Excel:这是我当前在 Excel 上的代码:

Sub getDataFromOutlook()

'~~Declarations~~'
Dim OutlookApp As Outlook.Application
Dim OutlookNamespace As Namespace
Dim Folder As MAPIFolder
Dim OutlookMail As Variant
Dim i As Integer

'~~Set email to be saved~~'
Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders("SAMPLE")

i = 1


For Each OutlookMail In Folder.Items
'~~Write to Excel~~'
If OutlookMail.ReceivedTime >= Range("email_Receipt_Date").Value Then
    Range("email_Subject").Offset(i, 0).Value = OutlookMail.Subject
    Range("email_Subject").Offset(i, 0).Columns.AutoFit
    Range("email_Subject").Offset(i, 0).VerticalAlignment = xlTop
    Range("email_Date").Offset(i, 0).Value = OutlookMail.ReceivedTime
    Range("email_Date").Offset(i, 0).Columns.AutoFit
    Range("email_Date").Offset(i, 0).VerticalAlignment = xlTop
    Range("email_Sender").Offset(i, 0).Value = OutlookMail.SenderName
    Range("email_Sender").Offset(i, 0).Columns.AutoFit
    Range("email_Sender").Offset(i, 0).VerticalAlignment = xlTop
    Range("email_Body").Offset(i, 0).Value = OutlookMail.Body
    Range("email_Body").Offset(i, 0).Columns.AutoFit
    Range("email_Body").Offset(i, 0).VerticalAlignment = xlTop

    i = i + 1
End If

Next OutlookMail

'~~Set to Null~~'
Set Folder = Nothing
Set OutlookNamespace = Nothing
Set OutlookApp = Nothing

End Sub

Have a look at this post:看看这个帖子:

How to copy Outlook mail message into excel using VBA or Macros 如何使用 VBA 或宏将 Outlook 邮件消息复制到 Excel 中

I think it should give you what you need (scroll down toward the bottom).我认为它应该给你你需要的东西(向下滚动到底部)。

Have you tried Attachments ?你试过Attachments吗? I haven't had the need to do this but that's where I'd put my initial effort.我不需要这样做,但这就是我最初努力的地方。

MailItem.Attachments.Item(0) let's you work with the first attachment. MailItem.Attachments.Item(0)让您处理第一个附件。

Since your variable OutlookMail holds a MailItem , the first thing I would try is...由于您的变量 OutlookMail 持有MailItem ,我会尝试的第一件事是......

ActiveSheet.Pictures.Insert(OutlookMail.Attachments.Item(0))

The second thing I would try is searching for an answer.我会尝试的第二件事是寻找答案。

Pulling pictures from emails and inserting pictures into Excel are not obscure tasks so there will be many detailed examples available to those who look for them.从电子邮件中提取图片并将图片插入 Excel 并不是一项艰巨的任务,因此寻找它们的人可以使用许多详细的示例。

I'm reminded of my grandmother's response when I'd ask if my skateboard was in the front yard.当我问我的滑板是否在前院时,我想起了我祖母的回答。 "Look with your eyes, not your mouth", is what she'd tell me. “用你的眼睛看,而不是你的嘴”,这是她告诉我的。 That feels appropriate here.在这里感觉很合适。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM