Consulting

Results 1 to 5 of 5

Thread: Automatically Change Deleted Email To Read - Non Default Mailbox

  1. #1

    Automatically Change Deleted Email To Read - Non Default Mailbox

    How do I take the script below and modify it so that it works with a non-default Outlook mailbox. Basically...I have 2 mailboxes (work & Hotmail) linked to my Outlook software on my laptop. My goal is to have email placed in the "Deleted Items" folder to automatically change to "Read". The below script works great for the default account (work) but...how do I get it to work with my Hotmail account?

    ______________________________________________________________
    Dim WithEvents olkFld As Outlook.Items


    Private Sub Application_Quit()
    Set olkFld = Nothing
    End Sub

    Private Sub Application_Startup()
    Set olkFld = Session.GetDefaultFolder(olFolderDeletedItems).Items
    End Sub

    Private Sub olkFld_ItemAdd(ByVal Item As Object)
    Item.UnRead = False
    Item.Save
    End Sub
    _________________________________________________

    Any help would be greatly appreciated and...thank you in advance for your time!

  2. #2
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    You can point to any mailbox by starting with "name of mailbox".

    Set olkFld = Session.Folders("name of mailbox").Folders("Deleted Items").Items
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  3. #3
    Quote Originally Posted by skatonni View Post
    You can point to any mailbox by starting with "name of mailbox".

    Set olkFld = Session.Folders("name of mailbox").Folders("Deleted Items").Items
    Wow, thank you very much…it worked! I was able to swap your line of code out with the line of code in my original and it automatically marked email in the “Deleted Items” folder, in my Hotmail account as “read”. The only problem is…when I tried to input your version in the code along with the original version…it only marked the items in my default account as read…I guess once it marked the items in the default account it stopped. How can I incorporate your line into the original script? Below is what I tried but…it didn’t work.

    *************************************************************************** ***********
    Dim WithEvents olkFld As Outlook.Items

    Private Sub Application_Quit()
    Set olkFld = Nothing
    End Sub

    Private Sub Application_Startup()
    Set olkFld = Session.GetDefaultFolder(olFolderDeletedItems).Items <-- My Work Account
    Set olkFld = Session.Folders("name of mailbox").Folders("Deleted Items").Items <-- My Hotmail Account
    End Sub

    Private Sub olkFld_ItemAdd(ByVal Item As Object)
    Item.UnRead = False
    Item.Save
    End Sub
    *************************************************************************** ***********

  4. #4
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    olkFld cannot represent two sets of items.

    Set olkFld = Session.GetDefaultFolder(olFolderDeletedItems).Items
    Set olkFld = Session.Folders("name of mailbox").Folders("Deleted Items").Items
    You will need to duplicate the code.

    Dim WithEvents olkFld As Outlook.Items
    Dim WithEvents olkFld2 As Outlook.Items
    
     Private Sub Application_Quit()
     Set olkFld = Nothing
     Set olkFld2 = Nothing
     End Sub
    
     Private Sub Application_Startup()
     Set olkFld = Session.GetDefaultFolder(olFolderDeletedItems).Items ' <-- My Work Account
     Set olkFld2 = Session.Folders("name of mailbox").Folders("Deleted Items").Items ' <-- My Hotmail Account
     End Sub
    
     Private Sub olkFld_ItemAdd(ByVal Item As Object)
     Item.UnRead = False
     Item.Save
     End Sub
     
     Private Sub olkFld2_ItemAdd(ByVal Item As Object)
     Item.UnRead = False
     Item.Save
     End Sub
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code. http://www.cpearson.com/excel/DebuggingVBA.aspx

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

  5. #5
    Quote Originally Posted by skatonni View Post
    olkFld cannot represent two sets of items.

    Set olkFld = Session.GetDefaultFolder(olFolderDeletedItems).Items
    Set olkFld = Session.Folders("name of mailbox").Folders("Deleted Items").Items
    You will need to duplicate the code.

    Dim WithEvents olkFld As Outlook.Items
    Dim WithEvents olkFld2 As Outlook.Items
    
     Private Sub Application_Quit()
     Set olkFld = Nothing
     Set olkFld2 = Nothing
     End Sub
    
     Private Sub Application_Startup()
     Set olkFld = Session.GetDefaultFolder(olFolderDeletedItems).Items ' <-- My Work Account
     Set olkFld2 = Session.Folders("name of mailbox").Folders("Deleted Items").Items ' <-- My Hotmail Account
     End Sub
    
     Private Sub olkFld_ItemAdd(ByVal Item As Object)
     Item.UnRead = False
     Item.Save
     End Sub
     
     Private Sub olkFld2_ItemAdd(ByVal Item As Object)
     Item.UnRead = False
     Item.Save
     End Sub
    Thank you VERY MUCH!!! That works perfectly!!! Really do appreciate it!

Posting Permissions

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