0

This code is executed every time I select a message. I want this code to be executed only when I am composing new mail/replying/forwarding.

Private Sub Application_ItemLoad(ByVal Item As Object)
    Dim oAccount As Outlook.Explorer
    If TypeName(Item) = "MailItem" Then
        MsgBox ("this is mail")
        Set oAccount = Application.ActiveExplorer   
        MsgBox (oAccount.CurrentFolder.FolderPath)
    End If
End Sub

What I am trying to achieve: When composing mail from specific account (account@mail.com) add recipient in CC field.

I am a noob in programming.

Community
  • 1
  • 1
Art
  • 3
  • 3
  • See this post: https://stackoverflow.com/questions/44019988/setting-the-sender-email-address-according-to-the-recipient/44033922#44033922 – Kostas K. Aug 30 '17 at 13:51
  • What is it exactly that you are trying to achieve? – Dmitry Streblechenko Aug 30 '17 at 14:24
  • Thanks for your replies guys. What i am trying to achieve is: When someone is trying to compose a mail from specific account (account@mail.com) then automatically needs to be added recipient in CC field. if composing from any other configured emails account nothing should happen. If that make sense... thanks again for any help here guys... – Art Aug 30 '17 at 14:35
  • The easiest way to do this would be not to hook into the ItemLoad but the ItemSend event, i.e. check right before the mail is sent: https://msdn.microsoft.com/de-de/library/office/ff865076.aspx – LocEngineer Aug 30 '17 at 15:05
  • Kostas K.: Any clue where to specify in that particular code the email address i want to put in CC field? Sorry for the noob question. – Art Aug 30 '17 at 15:09
  • LocEngineer: unfortunately changes has to be made before before person will click send button so they could actually see what they are sending... – Art Aug 30 '17 at 15:13

1 Answers1

0

You can test the MailItem.Sent property to determine whether composing mail or reading received mail.

Private Sub Application_ItemLoad(ByVal Item As Object)

    Dim oAccount As Outlook.Explorer

    If TypeName(Item) = "MailItem" Then

        If item.Sent Then
            MsgBox "Not for processing"
        Else
            MsgBox "Processing this mail"
            Set oAccount = Application.ActiveExplorer   
            MsgBox (oAccount.CurrentFolder.FolderPath)
        End If

    End If

End Sub
niton
  • 8,771
  • 21
  • 32
  • 52