Log in

View Full Version : Userform prompt to move mailitem based on change in unread property



Seth118
08-14-2015, 07:41 AM
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.

Seth118
08-17-2015, 08:40 AM
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