将格式化的Excel范围粘贴到Outlook任务中 [英] Paste formatted Excel range into Outlook task

查看:129
本文介绍了将格式化的Excel范围粘贴到Outlook任务中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试创建一个子程序,该子程序将从Excel选择中获取一些信息,并在Outlook上创建一个新任务.任务的主体应具有第一个单元格中的注释(它已经执行了),但在我要粘贴该区域(在Excel中查找该区域之前)之前,应先添加注释,然后再粘贴范围.

I've been trying to create a sub that would take some information from an Excel selection and create a new task on Outlook. The body of the task should feature the comment from the first cell (which it already does) but before all that I want to paste the range as it looks in Excel, then the comment, and then again, the range.

这是我的代码:

Sub CreateReminder()

Dim olApp As Object
Dim olRem As Object
Dim myRange As Range
Dim contact As String
Dim company As String
Dim city As String
Dim state As String
Dim cmt As comment
Dim comment As String
Dim strdate As Date
Dim remdate As Date

Set olApp = CreateObject("Outlook.Application")
Set olRem = olApp.CreateItem(3)

Set myRange = Selection


If ActiveCell.comment Is Nothing Then
    Exit Sub
Else
    Set cmt = ActiveCell.comment
End If
company = myRange.Columns(1).Text
contact = myRange.Columns(2).Text
If InStr(contact, "/") <> 0 Then
contact = Left(contact, InStr(contact, "/") - 1)
End If
city = myRange.Columns(7).Text
state = myRange.Columns(8).Text
myRange.Copy
comment = cmt.Text
strdate = Date
remdate = Format(Now)

rangeaddress = myRange.Address
wrksheetname = ActiveSheet.Name

With olRem

.Subject = "Call " & contact & " - " & company & " - " & city & ", " & state
.display
 SendKeys "{TAB 9}"
 SendKeys "^{v}"
 .body = Chr(10) & comment & Chr(10)
 '.startdate = strdate
 '.remindertime = remdate
 '.reminderset = True
 '.showcategoriesdialog
 End With

 Set olApp = Nothing
 Set olRem = Nothing

 End Sub

如您所见,我能够使用SendKeys方法进行粘贴,但这有点像黑客,而不是……复杂.我确定还有另一种方法,有想法吗?

As you can see, I am able to paste using a SendKeys method, but it is sort of a hack, and not... sophisticated. I'm sure there's another way of doing it, any ideas?

我找到了将HTML粘贴到电子邮件中的代码,但是据我了解,邮件"项允许HTML,但任务"项不允许.

I found code for pasting as HTML to an email, but as I understand, the Mail item allows for HTML, but not the Task item.

推荐答案

Outlook使用Word作为电子邮件编辑器.您可以使用Word对象模型在消息正文上制作manipulatins. Inspector类的WordEditor属性返回Document类的一个实例(来自Word对象模型),该实例表示主体.您可以在第17章:使用项目中阅读有关此方法和所有可能方法的更多信息.身体.

Outlook uses Word as an email editor. You can use the Word object model for making manipulatins on the message body. The WordEditor property of the Inspector class returns an instance of the Document class (from the Word object model) which represents the body. You can read more about that way and all possible ways in the Chapter 17: Working with Item Bodies.

这样,您可以使用复制范围类的方法将范围复制到剪贴板.然后,您可以使用Word对象模型中的Paste方法将数据粘贴到表示邮件正文的文档中.

That way you can use the Copy method of the Range class to copy the range to the Clipboard. Then you can use the Paste method from the Word object model to paste data into the document which represents the message body.

这篇关于将格式化的Excel范围粘贴到Outlook任务中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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