Fulvio needs to use rules to move sent messages, but the sent items are not marked read when they are copied to other folders.
I’ve set up a rule for copying any message I send out to a local outbox folder (rather than the one on remote server). Therefore, I’ve uncheck the standard option “save a copy of sent messages”, as I don’t need to duplicate them remotely. Everything works fine: I have no longer remote copies of sent emails, and I have the local ones, but these latter are now bolded as unread. So, I’d like to set my custom rule as: copy sent messages to the local outbox AND mark them as read. Yet it seems to be impossible….
It's not impossible to do, but it won't work with Rules. "After Sending" rules don't support custom actions, run a script, or marking items as read. However, you can use VBA to mark sent items read.
Because the sent item is not in the default data file, you'll need to use the code at Use a folder in another pst or Mailbox to identify the data file. Paste it and the code below into the ThisOutlookSession module in the VB Editor.
Change this line: Set Items = GetFolderPath("New PST\Sent Items").Items to reflect the data file name in the folder list and the folder name you are moving the sent item to.
Code Sample: Mark Moved Messages as Read
To test this code, click in the Application_Startup module and press Run to start it without restarting Outlook. Don't forget to get the GetFolderPath function from Use a folder in another pst or Mailbox.
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Set Items = GetFolderPath("New PST\Sent Items").Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Mark deleted items read automatically
To mark messages read as they are moved into a folder within the mailbox, such as the deleted items folder, use the following code sample.
To use the junk mail folder, use
Set Items = Ns.GetDefaultFolder(olFolderJunk).Items
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim Ns As Outlook.NameSpace
Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderDeletedItems).Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Move sent messages using VBA
This code sample moves the sent messages using VBA, rather than a rule.
If the folder you are moving the sent items to is in a different pst file, you'll need the GetFolderPath function at Use a folder in another pst or Mailbox.
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Set Items = Session.GetDefaultFolder(olFolderSentMail).Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Set MovePst = GetFolderPath("NewPST\Sent Items")
Item.UnRead = False
Item.Move MovePst
End Sub
How to use the Macro
First: You will need macro security set to low during testing.
To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security. If Outlook tells you it needs to be restarted, close and reopen Outlook. Note: after you test the macro and see that it works, you can either leave macro security set to low or sign the macro.
Now open the VBA Editor by pressing Alt+F11 on your keyboard.
To use the macro code in ThisOutlookSession:
- Expand Project1 and double click on ThisOutlookSession.
- Copy then paste the macro into ThisOutlookSession. (Click within the code, Select All using Ctrl+A, Ctrl+C to copy, Ctrl+V to paste.)
Application_Startup macros run when Outlook starts. If you are using an Application_Startup macro you can test the macro without restarting Outlook by clicking in the first line of the Application_Startup macro then clicking the Run button on the toolbar or pressing F8.
More information as well as screenshots are at How to use the VBA Editor.
More Information
More VBA samples that mark moved message as read are at:
Marking Sent Items as Read How to mark messages read when they are moved to multiple folders (WindowsITPro)
E-Mail: Mark as read Mark as read when moved to a subfolder of the Inbox (vboffice.net)
Jake says
I'm trying to combine two of the above subs and mark both the sent items and deleted items as read. But can only get one to work at a time. Here is what I have:
Private WithEvents Items As Outlook.ItemsPrivate Sub Application_Startup()
Set Items = GetFolderPath("JL RRT\Sent Items").Items
Dim Ns As Outlook.NameSpace
Set Ns = Application.GetNamespace("MAPI")
Set Items = Ns.GetDefaultFolder(olFolderDeletedItems).Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
MarkRead Item
End Sub
Private Sub MarkRead(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
A R says
I'm hoping to use this in combination with a rule to move a copy of each sent email to my inbox (as noted here: https://www.makeuseof.com/tag/auto-cc-bcc-outlook-gmail/ ) and automatically marking them as read, but am not quite sure how to update the example rule above to account for that. Can you point me in the right direction?
Diane Poremsky says
I think you'll need to use an item add macro to mark messages to you, sent from you, as read.
Elton John says
Don't be stupid, Outlook has an option on the sent items, above the search section there are options, All, Unread and others. just click on the unread option then select the item that you don't want to appear as unread, and that's it.
Diane Poremsky says
it's easier just to select all and mark all as read - but why do it manually when you can automate it?
Burak says
This was really helpfull Diane. Thank you. i got it working with a combination of "Move sent messages using VBA" and "Mark Moved Messages as Read" with 10+ folders. Works like a charm
Tony Edwards says
I am struggling to get this to work within Outlook 2010 - i have an IMAP account and the Outlook Data File set as default - yet anything that is copied into the sent items of the Data File is still unread. What could I be doing wrong?
Diane Poremsky says
Are you using the macro to mark the messages as read? What are you using for Set Items = GetFolderPath("New PST\Sent Items").Items ? It should be the display name of the data file, as seen in the folder list and the name of the sent folder - should be Sent Items if a pst file, could be something else in an IMAP account. You also need macro security on low for the macro to run.
Tony Edwards says
This is what I have so far - I cannot seem to get the Function right
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Set Items = GetFolderPath("Outlook Data FileSent Items").Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Diane Poremsky says
what happens when you try? Did you add the function at the end of the module (or in a new module named Functions? ) https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/#GetFolderPath
Assuming the missing slash in the path is wordpress's fault -
Set Items = GetFolderPath("Outlook Data FileSent Items").Items
Amit Singh says
actually it happens when we make new pst in same outlook,Though the above solution provided is ok,but we can do one more thing to remove existing pst,and restart outlook.. then all emails configuration will get download in new pst ... and then you can add removed pst in outlook .. hope it will work correctly
Willie Oosthuizen says
Thank you for your help, unfortunately I cannot seem to get it to work. I must be doing something wrong. I created a rule to automatically move emails from my inbox to a subfolder on a second OST file. I wish for it to be marked as "READ" as soon as it is moved but no luck. Please help
Diane Poremsky says
sorry I missed this earlier. You need to reference the second date file:
Private Sub Application_Startup()
Set Items = GetFolderPath("other@ost.name\Foldername").Items
End Sub
AbdulSalam says
Hi Diana,
Thanks for script. I have tried to use the script without success. My case is the following:
• I checked out save forwarded messages and save copies of messages in the sent items folder from outlook options
• I created a rule which apply after I send a massages to move a copy to "sent items" folder for massages which assigned a specific category
• The rule works fine, but when the messages moved to the “sent items” folder, it shows “unread”
• Can you help me to write a script to make it “read” once the massages moved to the “sent items” folder
Thanks
AbdulSalam
Diane Poremsky says
The script needs to look at the folders you move the messages to - if its the default sent items folder, you'd use this as the app startup macro to watch the sent items folder:
Private Sub Application_Startup()
' this is the folder the rule is moving sent messages to
Set Items = Session.GetDefaultFolder(olFolderSentMail).Items
End Sub
norbertlars says
hey,
so annoying this latest outlook 2013 :(
i think there is a problem there ( at Microsoft ) and they want to get rid of clients as fast as possible
as far as i can see best options/settings were done in outlook 2007 where all 3 of my main problems were perfect: exchange / pst / theme colors. outlook 2010 started to force an online mailbox and when i think of my work address with a PST of 17GB this is impossible :( so i must use this local storage.
now outlook 2013 is crazy with the sent items leaving them on server FFS who could have designed this thing ? i think there are software architects that use their brain for something. okay i can understand that they want to force people to move to cloud ( they do this since 2-3 years ago ) but leave at least some ways ( even with lots of configurations ) for the rest to set things up on other ways
so i now use outlook 2013, rules to move mails from inbox to pst folders, rule to move sent items, rule to ...rule ...
yesterday i knock on the bright white themes :( so annoying, now i just meet the delete/flag issue. i`m so close to move back to outlook 2010 only for this 3 issues ( at least there you could find options to set things they way you like )
so disappointing :( hope 2016 is better
Gus says
Hi! I'm using this code for a long time, however my Office has been upgraded today to the 2013 version and it's no longer marking sent items as read. Any trick?
Diane Poremsky says
Was the macro security reset to signed macros only? File, Options, Trust Center, Macro Security to check.
Jason says
Hi Diane
Wondering if you would be able to help me after coming across your webpage. I've setup a rule to move all my imap outgoing sent mail to my 'Sent Items' within my personal folders, i.e. to keep a backup using the local pst. However, the rules do not allow you to mark the sent item as read once transferred across, hence why I found you page. I applied the following code within the 'ThisOutlookSession' in the VBA Editior. I've changed the GetFolderPath address as it appears in outlook. However, to no avail as I keep getting 'Compile error: Sub or Function not defined'. I suspect this is because the path is incorrect - lost as I'm defining as it appears in outlook. Any pointers would be gratefully appreciated!
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Set Items = GetFolderPath("Personal Folders\Sent Items").Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Diane Poremsky says
Did you get the getfolderpath function from https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/#GetFolderPath ?
Stephane says
Hi Diane,
Thanks a lot for your time, it's almost perfect :-p !
In my case, I have two Inbox (two IMAP accounts). So it's working fine for the first Inbox, but how to do I tell the macro to also mark as read the mails in the 2nd sent folder ?
I have added a 2nd "items" (called Items2) in Application_Startup with the 2nd patch, but how should I invoke it in the Items_ItemAdd function ?
Thank you for your help !
Diane Poremsky says
To add another folder you need to repeat these lines, using a different name (Items2 is fine)
Private WithEvents Items2 As Outlook.Items
Private Sub Items2_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Plus, add the folder to the application start up macro:
Set Items = GetFolderPath("other datafile\Sent Items").Items
Another way is to use the following format for each itemsadd macro, calling a shared macro. For this macro, it doesn't make much difference, but if the code was longer it could make it easier to read and update as well as keep the file smaller.
Private Sub Items_ItemAdd(ByVal Item As Object)
MarkRead Item
End Sub
Private Sub MarkRead(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Fred Sawtelle says
I appreciate the sharing of your time and expertise. Thank you!
Fred Sawtelle says
I'd never given it any thought until you asked. Inbox is where I expect to find anything that needs my attention. I could set "Unread" as the default selected folder, I guess. But with Inbox I'm able to see the flow of a group conversation at a glance. With, say, five people discussing a topic it's important to me to see their comments in order, especially if I come in in the middle of it. Trying to follow it through separate folders would be frustrating, especially when there are some dead-end branches on the conversation (i.e. not everyone replies to the latest). Outlook probably provides a way of moving through a thread, but if so I've never used it; I rely on the newest-first display of Inbox to show me at a glance what's going on. What do you suggest?
Diane Poremsky says
There are two ways to handle it:
1. Don't file mail into a bunch of folders. Leave everything in the inbox and use Quick Steps to move mail after you've read it - i use just a couple of folders and dump almost everything into one folder called Completed. If i need to find mail to/from a specific person, i use instant search or a search folder.
2. Use rules to file mail and use the unread search folder to read it. As long as you use the By Date (Conversations) view, it will show all messages in the conversation. (Default view is by folder).
Fred Sawtelle says
I'm using 2013. Choosing the "Mark as read" option marks both of them as read. I need the one in Inbox to stay unread.
Diane Poremsky says
Oh. That limits your options. Is there a reason why you need copies of the messages left in the inbox?
Fred Sawtelle says
I have a subfolder of Inbox named "Coworkers" which in turn contains several folders named for coworkers. Rules send a copy of email from each to their respective folders. I want to mark all those emails as read while leaving the ones in Inbox unread. You've explained clearly what to do here for an individual folder. Is there a way to do it for multiple folders, short of creating an instance of Outlook.Items and an ItemAdd eventhandler for each one? For example, can I say in effect, "Mark as read everything that goes into any of the subfolders of this folder"?
Diane Poremsky says
Rules has an option to mark as read... which version of Outlook are you using?
Stephanie Hudson says
With the code, all new mail in my folder is being marked as read, not just the newly sent mail. How can I alter the code so that only the mail sent from myself is marked as read.
Details:
I'm wanting to keep conversation threads together, including sent mail. Ideally I want all this mail in my inbox until I decide I'm done with it and save it to another folder elsewhere. That is, I want all incoming mail and sent mail in the same "inbox" folder. Right now, I'm doing that in a folder directly below Outlook's inbox called "_My Inbox_".
A. I have a rule: After I send a message, move a copy to the "_My Inbox_" folder.
B. I have a bunch of other rules handling mail that can go to other folders or the trash.
C. My last rule is: After a message arrives, move it to the "_My Inbox_" folder.
D. In Mail Options, Save messages settings, I have "When replying to a message that is not in the Inbox, save the reply in the same folder" ticked (true).
E. In Mail Options, Save messages settings, I have "Save copies of messages in the Sent Items folder" NOT ticked (false).
-------
What's happening is that the Sent mail is Unread.
I tried adding a rule to mark mail from me (sent) as read, but this doesn't work as the mail just gets moved there, it doesn't actually "arrive" as the rule expects.
-------
F. So, I found your code and have applied it. However, now ALL mail coming to "_My Inbox_" is marked as read.
How can I alter the code so that only the mail sent from myself is marked as read.
Diane Poremsky says
Remove the rules that touch sent items and mark them read. Use the Move sent messages using VBA macro to move the message and mark it as read.
Use this as the move to location:
Set MovePst = Session.GetDefaultFolder(olFolderInbox)
Stephanie Hudson says
Am I putting that in the Application_Startup()? I currently have:
Private Sub Application_Startup()
Set Items = Session.GetDefaultFolder(olFolderInbox).Folders("_My Inbox_").Items
End Sub
Sorry, this is my first time with VBA in Outlook. Only used it in Excel and Access before.
Thanks.
Diane Poremsky says
The folder in the application start up is the one Outlook is watching. The folder you are moving sent items to is identified as the MovePst folder: (movepst may not make sense if you aren't moving it to a pst, but it's only a variable name and will work)
Set MovePst = GetFolderPath("NewPST\Sent Items")
If the folder you are moving mail to is a subfolder of the inbox and is named _My_Inbox_ then you want the movepst line to be
Set MovePst = Session.GetDefaultFolder(olFolderInbox).Folders("_My Inbox_").Items
Stephanie Hudson says
It's working now. Thank you so much for your help! I really appreciate it.
Chris says
My code is this but it gives me " object variable or with block variable not set 91" - What is wrong?
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim Items As Outlook.Items
Set Items = GetFolderPath("C:\Users\cc580e\Desktop\Chirag - Personal Folders(1).pst\Sent Items").Items
MsgBox "test"
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function
GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function
Diane Poremsky says
getfolderpath path is wrong, should be the display name and folders as it appears in the folder list.
Marek says
I don't think so Diane. I've already tested it with "Sent Items" and I am getting error: Run-time error 91. https://1drv.ms/1cPCjOE
Diane Poremsky says
If you are getting the when Outlook restarts or when you click in Application_Startup and click Run, it means the macro can't find the folder. Replace it with archive or one of the other names with only ASCII characters and click Run in the App Startup macro.
Marek says
Once again thank you Diane for your patience, but maybe I am stupid enough because after I am hitting RunSub/UserForm(F5) button, nothing is happend. I made two screenshots of my project/outlook. If you have a time, please look at this. https://1drv.ms/1cPCjOE Maybe you will find something what I am still missing...
Just for testing purpose i have used this guide https://msdn.microsoft.com/en-us/library/office/ff869298.aspx and message box appears correctly.
Diane Poremsky says
I'm guessing its the localization that is the problem. You tried it both with the localized name and "Sent Items"?
Marek says
Thank you for an answer but I did exactly what you wrote without success. Messages in Sent folder still remain marked as unread. Please can you check my full code:
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Set Items = GetFolderPath("Personal Folders\Sent Items").Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function
GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function
Diane Poremsky says
It works here. Did you click in Application startup macro and click run to kick start it?
Try adding msgbox "Working" as the first line of the itemadd macro - when the macro fires the message box will come up. That will tell us if its working.
Private Sub Items_ItemAdd(ByVal Item As Object)
msgbox "Working"
Item.UnRead = False
Item.Save
End Sub
Charitha says
I think you should give the folder name instead of giving Sent Items
Set Items = GetFolderPath("Personal Folders\Sent Items").Items
eg. Set Items = GetFolderPath("Personal Folders\Test").Items
Diane Poremsky says
In this example, the person who requested the macro wanted to move the mail from the sent items folder in one data file to the sent items folder in another data file, that is why i used the sent folder name.
If you are keeping it in the same data file, but moving to a different folder you would use getdefaultfolder instead:
Dim NS As Outlook.NameSpace
Set NS = Application.GetNamespace("MAPI")
'folder is subfolder of sent items
Set Items = NS.GetDefaultFolder(olFolderSentMail).Folders("Test")
or
' same level as sent
Set Items = NS.GetDefaultFolder(olFolderSentMail).parent.Folders("Test")
Marek says
No, as I wrote before, I had only insert new "Module/Class Module" Right now I try paste code as you mention but nothing is happening. "Unread" message still remain in Sent folder... No matter if I hit F5 key or Outlook was closed/reopened.
Diane Poremsky says
After you paste it in ThisOutlookSession, you need to click in the Application Startup macro and press the run button - this will start the macro without actually restarting outlook.
Marek says
Hello Diane, I dont know where I am doing mistake but I cannot make this to work. I just copy/paste Martins code from September 25. where I only changed GetFolderPath to right PST folder but i am getting this error: "Compile error: Only valid object module" (Private WithEvents Items... line is in red color). In ThisOutlookSession have I insert Module or Class Module? When I try to insert Class module I am not able to test/save project...
Please can you provide whole working code - with GetFolderPath? Thank you in advance. Marek
Diane Poremsky says
Did you try pasting it in ThisOutlookSession? Double click on ThisOutlooksession on the left to open it on the right side of the editor.
Chris Gilbert says
Don't know if anyone is reading this old thread, but I think if I turn off the save copy in Sent folder in Email Options and handle everything through Rules, then my Journal can't be used to save incoming and outgoing emails as entries there for record-keeping purposes which I find valuable for recreating my work for billing purposes.
Diane Poremsky says
It's possible - i have not tested it with journaling, in part because the journal is broken in Outlook 2010 and sent to death row in 2013.
Martins says
P.S. I try to run it for sent mails that are moved to Inbox subfolders..
Thanks again!
Diane Poremsky says
This part needs to be at the top of ThisOutlookSession.
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Set Items = GetFolderPath("New PST\Sent Items").Items
End Sub
Also, you only need the GetFolderPath function from the bottom of the other page, not all of the code on the page. (I'll fix my instructions.)
Martins says
Hi Diane,
I try to get this work, but it comes back with: Compile error: "Invalid attribute in Sub or Function" and marks "WithEvents Items As Outlook.Items"
Thanks for help!
My full code:
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Set Items = GetFolderPath("New PST\Sent Items").Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function
GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function
Diane Poremsky says
Make sure you change the path here to the actual pst name folder -
Set Items = GetFolderPath("New PST\Sent Items").Items
and it should work (when you put the first part at the top of =ThisOutlookSession as per my other comment). You need just the code in the comment (I removed the stuff you don't need, to reduce confusion and make it easier to read.)
Diane Poremsky says
Make sure you change the path here to the actual pst name folder -
Set Items = GetFolderPath("New PST\Sent Items").Items
and it should work (when you put the first part at the top of (ThisOutlookSession as per my other comment). You need just the code in the comment (I removed the stuff you don't need, to reduce confusion and make it easier to read.)
Stuart says
Hi Diane
I got the code in to mark all the emails as read when sent from one email address and stored in a defined folder.
Now how do I start a new project to do the same thing for the other email address and its defined folder.
I don't know how to start a new project.
using outlook 2007
thanks
Fulvio says
Great! It works perfectly!
Thanks a million.
Fulvio says
Dear Diane,
said that I'm quite far from being a VBA expert (in fact, this is my very first time), I tried to write down in sequence, under ThisOutlookSession module, what you indicated, following the instructions for replacing the string as well. As soon as I try to run the module to test it, I got an error message (translating from italian): "Invalid attribute within Sub or Function". could you help me further? Thanks
Hereafter what is currently in my editor:
Function GetFolderPath(ByVal FolderPath As String) As Outlook.Folder
Dim oFolder As Outlook.Folder
Dim FoldersArray As Variant
Dim i As Integer
On Error GoTo GetFolderPath_Error
If Left(FolderPath, 2) = "\\" Then
FolderPath = Right(FolderPath, Len(FolderPath) - 2)
End If
'Convert folderpath to array
FoldersArray = Split(FolderPath, "\")
Set oFolder = Application.Session.Folders.Item(FoldersArray(0))
If Not oFolder Is Nothing Then
For i = 1 To UBound(FoldersArray, 1)
Dim SubFolders As Outlook.Folders
Set SubFolders = oFolder.Folders
Set oFolder = SubFolders.Item(FoldersArray(i))
If oFolder Is Nothing Then
Set GetFolderPath = Nothing
End If
Next
End If
'Return the oFolder
Set GetFolderPath = oFolder
Exit Function
GetFolderPath_Error:
Set GetFolderPath = Nothing
Exit Function
End Function
Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Set Items = GetFolderPath("Cartelle Personali\Posta Inviata").Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Item.UnRead = False
Item.Save
End Sub
Diane Poremsky says
Do the colors of the text in the VBA editor more or less match the ones on the pages online? Red text is bad. Check the quotes and verify they are plain old quotes and not smart quotes.
Diane Poremsky says
Oh, and also put the Function code after the other code.
Claire says
Good to know--though I must say that Gmail's "mark as read" option for foldered mail is a bit quicker than VBA ;)
Diane Poremsky says
If you use rules to move mail, you can mark read using rules - but Outlook only lets you copy mail after sending and doesn't offer a mark as read option for it. (Don't ask me why - I think it should.)