vba 将格式化的 Excel 范围粘贴到 Outlook 邮件中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2512351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 11:27:29  来源:igfitidea点击:

Pasting formatted Excel range into Outlook message

excelvbaoutlook

提问by

I would like to paste a range of formatted Excel cells into an Outlook message.

我想将一系列格式化的 Excel 单元格粘贴到 Outlook 邮件中。

The following code (that I lifted from various sources), runs without error and sends an empty message.

以下代码(我从各种来源提取)运行时没有错误并发送一条空消息。

Sub SendMessage(SubjectText As String, Importance As OlImportance)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Dim iAddr As Integer, Col As Integer, SendLink As Boolean
'Dim Doc As Word.Document, wdRn As Word.Range
Dim Doc As Object, wdRn As Object

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

Set Doc = objOutlookMsg.GetInspector.WordEditor
'Set Doc = objOutlookMsg.ActiveInspector.WordEditor
Set wdRn = Doc.Range
wdRn.Paste

Set objOutlookRecip = objOutlookMsg.Recipients.Add("[email protected]")
objOutlookRecip.Type = 1
objOutlookMsg.Subject = SubjectText
objOutlookMsg.Importance = Importance

With objOutlookMsg
    For Each objOutlookRecip In .Recipients
        objOutlookRecip.Resolve
        ' Set the Subject, Body, and Importance of the message.
        '.Subject = "Coverage Requests"
        'objDrafts.GetFromClipboard
    Next
    .Send
End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub

回答by JP Alioto

I think you need to call .Saveon your Mail Item (objOutlookMsg) after you've made all the changes.

我认为您需要在完成所有更改后在您的邮件项目 (objOutlookMsg) 上调用.Save

回答by Shakey

Put .Display before .Send,

将 .Display 放在 .Send 之前,

Simple but Quick fix, your problem is the email is not refreshing with the pasted contents before it sends, forcing it to Display first gives it time...

简单但快速修复,您的问题是电子邮件在发送之前没有用粘贴的内容刷新,强制它首先显示给它时间......

Also make sure you have another macro which runs before this to Copy the Range into your clipboard...

还要确保您有另一个宏在此之前运行以将范围复制到剪贴板中...

回答by 76mel

There is a button in excel to do this, "Send to mail recipent" its not normally on the ribbon.

excel中有一个按钮可以执行此操作,“发送到邮件配方”通常不在功能区上。

You can also use the simple mapi built into office using the MailEnvelope in VBA

您还可以使用 VBA 中的 MailEnvelope 使用内置于 office 中的简单 mapi

.. a good article on what you are trying to do http://www.rondebruin.nl/mail/folder3/mail4.htm

.. 一篇关于你正在尝试做什么的好文章http://www.rondebruin.nl/mail/folder3/mail4.htm