Auto Reply with notes, email body and add CC

666 views Asked by At

I am try to CC second person but I am getting Error run-time 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

Thanks.

2

There are 2 answers

1
niton On BEST ANSWER

Try Recipient not Recipients

 Dim olRecipient As Outlook.Recipient
2
Eugene Astafiev On

The Add method of the Recipients class creates a new recipient in the Recipients collection. The parameter is the name of the recipient; it can be a string representing the display name, the alias, or the full SMTP e-mail address of the recipient.

If you run the following sample code in Outlook there is no need to create a new Application instance, use the Application property available in VBA out of the box.

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

Don't forget to call the Resolve method of the Recipient class after adding a new one. Or just the ResolveAll method of the Recipients class to resolve recipients against the address book.

See How to: Specify Different Recipient Types for a Mail Item for more information.