none
Problem with VBA Script to mark Sent Items as Read RRS feed

  • Question

  • Hello,

    I am acquainted with VBA scripting in Excel but I am new to VBA scripting in Outlook and firing events.

    I am saving sent items with a rule to a non-standard location and because of that they remain marked as unread. Trying to address this with a script. So I am running Outlook 2016 64bit I tried the code provided here

    https://www.slipstick.com/outlook/rules/mark-items-read/

    And yes I did also copy the GetFolderPath function from the other page.

    Immediately I run into an error saying that "Private WithEvents Items As Outlook.Items" is an invalid attribute for the sub or function. My guess is the code is too old and incompatible with Outlook 2016 x64.

    Second, I have a question. Under "New PST\blabla". I am trying to run this rule on a PST that is not the default place for Sent Items. What am I supposed to set "New PST" to? The name of the PST as it appears on the left-hand pane(I have it set to to the custom title "E-mail for John Doe")? Or the name of the PST file("john.doe@contoso.com.pst") as it exists on the disk?

    Also if this isn't right, what code should I use then?

    Thank you.


    Friday, January 20, 2017 8:23 AM

All replies

  • Hi Searinox,

    Since your question is VBA related, I'm moving it to the dedicated Outlook for Developer forum. There you should get more professional responses:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=outlookdev

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Regards,

    Ethan Hua


    Please remember to mark the replies as answers if they helped.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, January 23, 2017 9:27 AM
  • Hello Searinox,

    The VBA code listed in the article is well-formed and can be used in Outlook 2016. There were no breaking changes between Outlook versions. You may find the Getting Started with VBA in Outlook 2010 article helpful. 

    In VBA I'd suggest handling the ItemSend event and setting the SaveSentMessageFolder property of the MailItem class which allows to set a Folder object that represents the folder in which a copy of the e-mail message will be saved after being sent. So, you can handle the ItemAdd event of that folder for setting the UnRead property to false (like the macro from the article does).

    You can iterate over all stores in the profile using the Stores collection, see Working with Outlook Accounts, Stores, Folders and Items for more information. 


    profile for Eugene Astafiev at Stack Overflow, Q&A for professional and enthusiast programmers

    Monday, January 23, 2017 11:30 AM
  • Hi,

    >>Immediately I run into an error saying that "Private WithEvents Items As Outlook.Items" is an invalid attribute for the sub or function

    Where do you add the macro code? Please use the code in the ThisOutlookSession.

    >>What am I supposed to set "New PST" to?

    I think you should set it to the name showing in the pane.

    It works for me if I use something like:   Set MovePst = GetFolderPath("celesteli93@outlook.com\testFolder")

    Regards,

    Celeste


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, January 24, 2017 2:31 AM
    Moderator