Consulting

Results 1 to 5 of 5

Thread: Apply macro to new item in Sent Items folder

  1. #1

    Apply macro to new item in Sent Items folder

    Hi,

    I am using the code below to open a userform when an email is added to the sent items folder in Outlook 2013

    Private WithEvents Items As Outlook.Items

    Private Sub Application_Startup()
    Dim Ns As Outlook.NameSpace
    Set Ns = Application.GetNamespace("MAPI")
    'use the default folder
    Set Items = Ns.GetDefaultFolder(olFolderSentMail).Items
    End Sub

    Private Sub Items_ItemAdd(ByVal Item As Object)
    UserForm3.Show
    End Sub

    This code works fine and opens the userform. On the userform there are several buttons that I want be apply to apply to the item that landed in the sent item folder causing the userform to be opened e.g. on of the buttons will delete the email, another will save the email in MSG format in a specific folder etc. The problem I am having is how to 'select' the email to apply the other macros to.

    Any help would be appreciated as I'm new to coding and struggling with this one.

    Thanks

  2. #2
    I'm fully sorted by using the sort function, sorting by ascending senton date and then selecting the first item

  3. #3
    Is there a reason why you are not using
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    This code in the ThisOutloookSession folder will intercept the Send command and run your code with 'Item' being the message being sent.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  4. #4
    Using itemsend wouldn't work for what I am trying to do. Using the itemsend function would result in the code applying to the message before it is sent. As my code saves the message in MSG format I need the code to be applied after the message has been sent hence why I'm using itemadd

  5. #5
    VBAX Mentor skatonni's Avatar
    Joined
    Jun 2006
    Posts
    347
    Location
    Try declaring a global variable in a standard module.
    Option Explicit
    
    Public userformItem As Object
    
    Private Sub Items_ItemAdd(ByVal Item As Object)
        Set userformItem = Item
        UserForm3.Show
        Set userformItem = Nothing
    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.

Posting Permissions

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