Outlook events stop work randomly

Discussion in 'Coding' started by Pioytabu, Jul 8, 2018.

  1. Pioytabu

    Pioytabu

    Joined:
    Jul 8, 2018
    Likes Received:
    0
    I had the next vba program in outlook seesion. This works fine but stop works random and the event not fired when outlook not is closed for a days.

    Can help me please?

    This is my code


    Option Explicit
    Private WithEvents inboxItems As Outlook.Items

    Private Sub Application_Startup()
    Dim outlookApp As Outlook.Application
    Dim objectNS As Outlook.NameSpace

    Set outlookApp = Outlook.Application
    Set objectNS = outlookApp.GetNamespace("MAPI")
    Set inboxItems = objectNS.GetDefaultFolder(olFolderInbox).Items
    End Sub

    Private Sub inboxItems_ItemAdd(ByVal Item As Object)
    On Error GoTo ErrorHandler

    Dim Msg As Outlook.MailItem
    Dim MessageInfo
    Dim Result
    If TypeName(Item) = "MailItem" Then
    MessageInfo = "" & _
    "Sender : " & Item.SenderEmailAddress & vbCrLf & _
    "Sent : " & Item.SentOn & vbCrLf & _
    "Received : " & Item.ReceivedTime & vbCrLf & _
    "Subject : " & Item.Subject & vbCrLf & _
    "Size : " & Item.Size & vbCrLf & _
    "Message Body : " & vbCrLf & Item.Body
    Result = MsgBox(MessageInfo, vbOKOnly, "New Message Received")
    End If

    ExitNewItem:
    Exit Sub

    ErrorHandler:
    MsgBox Err.Number & " - " & Err.Description
    Resume ExitNewItem
    End Sub
     
    Pioytabu, Jul 8, 2018
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.