Consulting

Results 1 to 4 of 4

Thread: make last message sent active (highlightied) in sent mail folder

  1. #1

    make last message sent active (highlightied) in sent mail folder

    I need to make the last message sent active or highlighted in the sent mail folder. This is what I have so far:

    Private Sub SentSave()
    Dim objOL As Object 'As Outlook.Application
    Dim objFolder As Object 'As Outlook.Folder
        'get current folder
        Set objOL = CreateObject("Outlook.Application")
        Set objFolder = objOL.ActiveExplorer.CurrentFolder
        Set objOL.ActiveExplorer.CurrentFolder = objFolder
        Set myOlApp = CreateObject("Outlook.Application")
        Set myNamespace = myOlApp.GetNamespace("MAPI")
        Set myOlApp.ActiveExplorer.CurrentFolder = myNamespace.GetDefaultFolder(olFolderSentMail)
        Application.ActiveExplorer.ClearSelection
        Application.ActiveExplorer.Activate
        
                          '<here I need to have the last item sent highlighted in the sentmail folder   
    
        'save emails to job folders using listbox
        UserForm1.Show
        'return to original folder
        Set objOL.ActiveExplorer.CurrentFolder = objFolder
    
    End Sub
    Any help would be appreciated.
    Chris

  2. #2
    Given that you have posted in an Outlook forum I assume we can expect that the macro is to be run in Outlook VBA, in which case you don't have to create a new Outlook application, you are already in Outlook.

    You don't need to select a message in order to process it, you merely have to identify it to the macro. The following will identify the latest item in the sent mail folder.

    Your Userform is a mystery so I cannot comment on that.

    Private Sub SentSave()
    Dim olItems As Items
    Dim olItem As Object
    
        Set olItems = Session.GetDefaultFolder(olFolderSentMail).Items
        olItems.Sort "[Received]", True
        
        '<here I need to have the last item sent highlighted in the sentmail folder
        Set olItem = olItems(1) 'You have it
            
        'save emails to job folders using listbox
        UserForm1.Show
    
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    Graham,
    Thanks for the code but, with out going into detail, I need it to work as described in the first post.

  4. #4
    In that case add
    Session.GetDefaultFolder(olFolderSentMail).GetExplorer.Display
    before
    Set olItems = Session.GetDefaultFolder(olFolderSentMail).Items
    to display the folder.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

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