Consulting

Results 1 to 2 of 2

Thread: Userform prompt to move mailitem based on change in unread property

  1. #1
    VBAX Newbie
    Joined
    Aug 2015
    Posts
    3
    Location

    Userform prompt to move mailitem based on change in unread property

    Hello all,

    So, I've got a business problem and came up with a solution...now i just need to get the code to work.

    Here is the goal: When the user selects a mail item (in inspector or explorer) and it changes from unread to read, a userform will pop up and ask which folder they would like to move that mailitem to. They click a button, and it moves that specific mailitem (which just changed its unread property to false) to the respective folder. This has taken quite some time so far, so please help.

    Here is what i have so far:
    Sub getselecteditems()
    End Sub
    
    
    Dim myolexplorer As Outlook.Explorer
    Dim myolselection As Outlook.Selection
    Dim selobject As myolselection.Item
    
    
        Set myolexplorer = Application.ActiveExplorer
        Set myolselection = myolexplorer.Selection
        
        If Me.myolselection.Count > 0 Then
        For x = 1 To myolselection.Count
        
            If myolselection.Class = olMail Then
                If myolselection.Item(x).UnRead = False Then
    
    
                    UserForm2.Show vbModal
                
                End If
            End If
        Next x
        End If
        
    End Sub
    The userform code looks like this:
    Private Sub CommandButton1_Click()
    On Error GoTo error_movemessage
    
    
        Dim myolapp As New Outlook.Application
        Dim mynamespace As Outlook.NameSpace
        Dim myinbox As Outlook.MAPIFolder
        Dim mydestfolder As Outlook.MAPIFolder
        Dim myitems As Outlook.Items
        Dim myitem As Object
        
        Set mynamespace = myolapp.GetNamespace("MAPI")
        Set myinbox = Session.GetDefaultFolder(olFolderInbox).Parent.Folders("RetainPermanently")
        Set myitems = myinbox.Items
        Set mydestfolder = myinbox
        Set myitem = Application.ActiveInspector.CurrentItem
        
        myitem.SaveSentMessageFolder mydestfolder
        Unload Me
        
    exit_CommandButton1_Click:
        Exit Sub
    error_movemessage:
    MsgBox "ERROR! " & Err.Description
    Resume exit_CommandButton1_Click
    
    
    End Sub
    Any help would be greatly appreciated.

  2. #2
    VBAX Newbie
    Joined
    Aug 2015
    Posts
    3
    Location
    New code to replace the first section:
    Private Sub Application_ItemLoad(ByVal Item As Object)
        If Item.Class = olMail Then
            If Item.UnRead Then
                UserForm2.Show vbModal
            End If
        End If
    End Sub

Tags for this Thread

Posting Permissions

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