使用Outlook VBA将电子邮件复制到剪贴板 [英] Copy email to the clipboard with Outlook VBA

查看:262
本文介绍了使用Outlook VBA将电子邮件复制到剪贴板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何将电子邮件复制到剪贴板,然后将其完整地粘贴到excel中?

How do I copy an email to the clipboard and then paste it into excel with the tables intact?

我正在使用Outlook 2007,但我想做同样的事情

I am using Outlook 2007 and I want to do the equivalent of


"Click on email > Select All > Copy > Switch to Excel > Select Cell > Paste". 


我很清楚Excel对象模型,但是除以下代码外,没有没有在Outlook中的经验。

I have the Excel Object Model pretty well figured out, but have no experience in Outlook other than the following code.

Dim mapi As NameSpace
Dim msg As Outlook.MailItem
Set mapi = Outlook.Application.GetNamespace("MAPI")
Set msg = mapi.Folders.Item(1).Folders.Item("Posteingang").Folders.Item(1).Folders.Item(7).Items.Item(526)


推荐答案

我必须承认我在Outlook 2003中使用了此功能,但是请查看它是否也可以在2007年使用:

I must admit I use this in Outlook 2003, but please see if it works in 2007 as well:

您可以使用 MSForms .DataObject 与剪贴板交换数据。在Outlook VBA中,创建对 Microsoft Forms 2.0对象库的引用,然后尝试以下代码(您当然可以将Sub()附加到按钮上,等等):

you can use the MSForms.DataObject to exchange data with the clipboard. In Outlook VBA, create a reference to "Microsoft Forms 2.0 Object Library", and try this code (you can of course attach the Sub() to a button, etc.):

Sub Test()
Dim M As MailItem, Buf As MSForms.DataObject

    Set M = ActiveExplorer().Selection.Item(1)
    Set Buf = New MSForms.DataObject
    Buf.SetText M.HTMLBody
    Buf.PutInClipboard

End Sub

在那之后,切换到Excel并按Ctrl-V-我们开始了!
如果您还想找到当前正在运行的Excel应用程序并使之自动化,请告诉我。

After that, switch to Excel and press Ctrl-V - there we go! If you also want to find the currently running Excel Application and automate even this, let me know.

总有一个有效的HTMLBody,即使邮件是以纯文本或RTF格式发送,Excel将显示HTMLBody incl中传达的所有文本属性。列,颜色,字体,超链接,缩进等。但是,不会复制嵌入的图像。

There's always a valid HTMLBody, even when the mail was sent in Plain Text or RTF, and Excel will display all text attributes conveyed within HTMLBody incl. columns, colors, fonts, hyperlinks, indents etc. However, embedded images are not copied.

此代码演示了要点,但并未检查MailItem是否确实是已选择。如果您还想使其适用于日历条目,联系人等,这将需要更多的编码。

This code demonstrates the essentials, but doesn't check if really a MailItem is selected. This would require more coding, if you want to make it work for calendar entries, contacts, etc. as well.

在列表中选择邮件就足够了视图,甚至不需要打开它。

It's enough if you have selected the mail in the list view, you don't even need to open it.

这篇关于使用Outlook VBA将电子邮件复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆