none
VBA Code Disables Automatic Send/Receive RRS feed

  • Question

  • The purpose of this post is to respectfully request clarification as to what appears to be an issue with the Outlook 2013 64-bit (on Win7) automatic Send/Receive.  This relates only to POP accounts as IMAP accounts seem to update real-time.

    That said, the following code executes upon starting Outlook and appears to disable automatic send/receive (see discussion below code):

    Dim WithEvents sync As Outlook.SyncObject
    
    '''=======================================Sync Event Handler================================================================'''
    Private Sub Initialize_handler(allAcctsSync As Boolean)
        If allAcctsSync = False Then
            Set sync = Application.Session.SyncObjects.AppFolders
            sync.Start
        End If
        If allAcctsSync = True Then
            Set sync = Application.Session.SyncObjects(1) 'All Accounts Group
            sync.Start
        End If
    End Sub
    
    '''=====================================Outlook Startup Script=============================================================='''
    Sub Application_Start()
        Initialize_handler (True)
    End Sub
    
    Sub Application_NewMail()
        Initialize_handler (False)
    End Sub
    
    '''=========================================SyncEnd() Event================================================================='''
    Sub Application_SyncEnd()
        Dim oDeletedItems As Outlook.Folder
        Dim SubFolders As Outlook.Folders
        Dim oItems As Outlook.Items
        Dim i As Long
    
        Set oDeletedItems = Application.Session.Folders.Item("aer@yahoo.com")
        Set SubFolders = oDeletedItems.Folders
        Set oDeletedItems = SubFolders.Item("Sent")
        Set oItems = oDeletedItems.Items
    
        For i = oItems.Count To 1 Step -1
            oItems.Item(i).Delete
            Next
        Set SubFolders = oDeletedItems.Folders
        For i = SubFolders.Count To 1 Step -1
            SubFolders.Item(i).Delete
            Next
    
        Set oDeletedItems = Application.Session.Folders.Item("aebe@aebr.com")
        Set SubFolders = oDeletedItems.Folders
        Set oDeletedItems = SubFolders.Item("Sent Items")
        Set oItems = oDeletedItems.Items
    
        For i = oItems.Count To 1 Step -1
            oItems.Item(i).Delete
            Next
        Set SubFolders = oDeletedItems.Folders
        For i = SubFolders.Count To 1 Step -1
            SubFolders.Item(i).Delete
            Next
    
        Set oDeletedItems = Application.Session.Folders.Item("aer@yahoo.com")
        Set SubFolders = oDeletedItems.Folders
        Set oDeletedItems = SubFolders.Item("Trash")
        Set oItems = oDeletedItems.Items
    
        For i = oItems.Count To 1 Step -1
            oItems.Item(i).Delete
            Next
        Set SubFolders = oDeletedItems.Folders
        For i = SubFolders.Count To 1 Step -1
            SubFolders.Item(i).Delete
            Next
    
        Set oDeletedItems = Application.Session.Folders.Item("aebe@aebr.com")
        Set SubFolders = oDeletedItems.Folders
        Set oDeletedItems = SubFolders.Item("Deleted Items")
        Set oItems = oDeletedItems.Items
    
        For i = oItems.Count To 1 Step -1
            oItems.Item(i).Delete
            Next
        Set SubFolders = oDeletedItems.Folders
        For i = SubFolders.Count To 1 Step -1
            SubFolders.Item(i).Delete
            Next
    
        Set oDeletedItems = Nothing
        Set oFolders = Nothing
        Set oItems = Nothing
    End Sub
    

    The idea of the code is - after receiving new mail - to permanently remove all messages from the mail servers.  Outlook deletes all messages, but those messages are placed in the "Trash" or "Deleted Items" folders on the respective servers.  The above code is an attempt to solve this problem. 

    At any rate, the code above appears to disable automatic send/receive insomuch that when the code is removed, automatic send/receive operates normally.  Conversely, if the code is active, automatic send/receive does not work.

    Please note, all groups ("All Accounts" and "App Folders") are configured properly.  Outlook currently updates 3 POP accounts, 1 IMAP account and 1 outlook.com pseudo-exchange account.

    Thus, the post serves to respectfully request clarification as to how this issue may be resolved that I may be able to implement the above code while continuing to automatically send/receive.  To that end, if there is VBA code which will automatically send/receive at a given time interval, such code would suffice for the immediate need.

    Thank you for your time and consideration.

    Cheers,

    alpo

    Thursday, June 27, 2013 3:59 AM

All replies

  • ...

    I'll give it a shot.


    Regards,
    Fermin
    What's life without whimsy?

    Tuesday, July 9, 2013 12:42 PM
  • Apparently this is a known issue pending resolution: 

    http://social.msdn.microsoft.com/Forums/office/en-US/7a20664c-7650-4d61-9d5f-13f1d929a8cd/outlook-2013-automatic-sendreceive-doesnt-work-with-the-sample-addin-below

    Wednesday, July 24, 2013 2:56 PM