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.
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.