自动回复笔记,电子邮件正文和添加CC

时间:2015-06-11 18:02:06

标签: vba outlook-vba outlook-2010

我正在尝试CC第二人,但我得到错误运行时间13 Type mismatch

Option Explicit
'// Auto Replay with notes and email body- run Action Script
Public Sub ReplywithNote(Item As Outlook.MailItem)
    Dim olInspector As Outlook.Inspector
    Dim olDocument As Word.Document
    Dim olSelection As Word.Selection
    Dim olReply As MailItem
    Dim olRecipient As Outlook.Recipient


    Set olReply = Item.ReplyAll
    olReply.Display

    Set olRecipient = myItem.Recipient.Add("omar")
        olRecipient.Type = olCC

    Set olInspector = Application.ActiveInspector()
    Set olDocument = olInspector.WordEditor
    Set olSelection = olDocument.Application.Selection

    olSelection.InsertBefore "Received, Thank you."

    '// Uncomment to send
    olReply.Send

End Sub

感谢。

2 个答案:

答案 0 :(得分:1)

“收件人”类的Add方法在“收件人”集合中创建新收件人。参数是收件人的名字;它可以是表示收件人的显示名称,别名或完整SMTP电子邮件地址的字符串。

如果在Outlook中运行以下示例代码,则无需创建新的Application实例,请使用开箱即用的VBA中提供的Application属性。

 Set myOlApp = CreateObject("Outlook.Application") // Application
 Set myItem = myOlApp.CreateItem(olMailItem)
 Set myRecipient = myItem.Recipients.Add ("Jon Grande")
 myRecipient.Type = olCC

添加新类后,不要忘记调用Recipient类的Resolve方法。或者只是Recipients类的ResolveAll方法来解析通讯录的收件人。

有关详细信息,请参阅How to: Specify Different Recipient Types for a Mail Item

答案 1 :(得分:1)

尝试收件人而不是收件人

 Dim olRecipient As Outlook.Recipient