View Full Version : [SOLVED:] Automatically Change Deleted Email To Read - Non Default Mailbox
DavidHaley
01-24-2017, 03:40 PM
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!
skatonni
01-25-2017, 11:06 AM
You can point to any mailbox by starting with "name of mailbox".
Set olkFld = Session.Folders("name of mailbox").Folders("Deleted Items").Items
DavidHaley
01-25-2017, 11:38 AM
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
*************************************************************************** ***********
skatonni
01-25-2017, 02:36 PM
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
DavidHaley
01-25-2017, 03:18 PM
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!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.