+ Reply to Thread
Results 1 to 2 of 2

VBA Outlook Delete Issue

Hybrid View

  1. #1
    Registered User
    Join Date
    03-30-2014
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    24

    VBA Outlook Delete Issue

    Hi

    Looking for assistance I have worked out how to reuse code to delete emails from a specified folder within outlook using Excel VBA. The emails are reports scheduled to the folder with attachments of various sizes

    For the test I have 6 emails of various sizes 148k, 2mb, 6mb, 634k, 57k, 18mb

    The vba code does seem to partially work as it moves the emails to the "deleted items", but only seems to move 3 emails (148k, 2 mb and 6mb) and not the rest, is their a restriction to the size, as a bit puzzled to this.

    I would like to eventually permanently delete the emails within the "deleted items", due to the size and save storage space

    See code below as it might be useful to another

    Public Sub Empty_IT_FileAutomationFolder()
    
    
        Dim objOwner As Outlook.Recipient 'new
        Dim nsSession As Namespace
        Dim fldInbox As Outlook.MAPIFolder
        Dim fldDBADatabaseInfo As MAPIFolder
        Dim olitem As Object
            
        Set nsSession = GetNamespace("MAPI")
        
        Set fldInbox = nsSession.GetDefaultFolder(olFolderInbox)
            
        Set objOwner = nsSession.CreateRecipient("Systems")
        objOwner.Resolve
           
        If objOwner.Resolved Then
            'MsgBox objOwner.Name
            Set fldInbox = nsSession.GetSharedDefaultFolder(objOwner, olFolderInbox)
        End If
          
        Set fldDBADatabaseInfo = fldInbox.folders("IT File Automation")
    
        For Each olitem In fldDBADatabaseInfo.Items
            olitem.Delete
        Next
           
        Set nsSession = Nothing
        Set fldInbox = Nothing
        Set fldDBADatabaseInfo = Nothing
        Set olitem = Nothing
    
    End Sub
    Really appreciate the time and assistance


    Man chun

  2. #2
    Registered User
    Join Date
    03-30-2014
    Location
    UK
    MS-Off Ver
    Excel 2016
    Posts
    24

    Re: VBA Outlook Delete Issue

    Hi wanted to say now resolved, and it appears a count was needed, see updated code

    
    Sub Empty_IT_FileAutomationFolderTest()
    
    
    Dim objOwner As Outlook.Recipient 'new
    Dim i As Long
    Dim nsSession As Namespace
    Dim fldInbox As Outlook.MAPIFolder
    Dim fldDBADatabaseInfo As MAPIFolder
    Dim olitem As Object
            
    Set nsSession = GetNamespace("MAPI")
    
    Set fldInbox = nsSession.GetDefaultFolder(olFolderInbox)
            
    Set objOwner = nsSession.CreateRecipient("Inbox Name")
    objOwner.Resolve
           
        If objOwner.Resolved Then
            'MsgBox objOwner.Name
            Set fldInbox = nsSession.GetSharedDefaultFolder(objOwner, olFolderInbox)
        End If
       
        Set fldDBADatabaseInfo = fldInbox.Folders("IT File Automation")
    
    
        While fldDBADatabaseInfo.Items.Count > 0
        For Each olitem In fldDBADatabaseInfo.Items
            olitem.Delete
        Next
    
        Wend
    
        Set nsSession = Nothing
        Set fldInbox = Nothing
        Set fldDBADatabaseInfo = Nothing
        Set olitem = Nothing
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Excel VBA email to Outlook; CC issue (Minor)
    By yawwwn in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2015, 05:13 AM
  2. Vba to send files via outlook issue
    By thaykhov in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-08-2015, 06:04 AM
  3. Outlook Attachment VBA issue
    By bullo1854 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-27-2014, 01:21 PM
  4. Reference issue with Outlook
    By kurtmcgill in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-18-2013, 05:30 AM
  5. exporting issue with outlook body in excel.
    By akulka58 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-01-2013, 02:26 PM
  6. Microsoft Outlook printing issue
    By jeskit in forum Outlook Formatting & Functions
    Replies: 0
    Last Post: 10-13-2011, 10:38 AM
  7. outlook 2003 view issue
    By coolhit in forum Outlook Formatting & Functions
    Replies: 2
    Last Post: 04-12-2011, 05:47 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1