C
Corey Thompson
I have created a button that is linked to a macro. The maco goes
through and moves the item to my archive folder.
However, when I have a message that has a completed flag, it fails. It
provides an error message about not being able to move unsent,
completed-flagged items (or something like that). I found this
completely bizzare.
Anyway, I figured that I'd be able to workaround it by unflagging it,
moving it, then re-flagging it as completed. The move now works, but
the mark-as-flagged does not.
Any ideas?
Code follows:
Sub MoveSelectedMessagesToFolder()
On Error Resume Next
Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objFolder = objInbox.Parent.Folders("Archive") 'Assume this is
a mail folder
If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation,
"INVALID FOLDER"
End If
If Application.ActiveExplorer.Selection.Count = 0 Then
'Require that this procedure be called only when a message is
selected
Exit Sub
End If
For Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
If objItem.FlagStatus = olFlagComplete Then
objItem.FlagStatus = olFlagMarked
' objItem.FlagIcon = olPurpleFlagIcon
objItem.Move objFolder
objItem.FlagStatus = olFlagComplete
objItem.FlagIcon = olNoFlagIcon
Else
objItem.Move objFolder
End If
End If
End If
Next
Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub
Corey Thompson
through and moves the item to my archive folder.
However, when I have a message that has a completed flag, it fails. It
provides an error message about not being able to move unsent,
completed-flagged items (or something like that). I found this
completely bizzare.
Anyway, I figured that I'd be able to workaround it by unflagging it,
moving it, then re-flagging it as completed. The move now works, but
the mark-as-flagged does not.
Any ideas?
Code follows:
Sub MoveSelectedMessagesToFolder()
On Error Resume Next
Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objFolder = objInbox.Parent.Folders("Archive") 'Assume this is
a mail folder
If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation,
"INVALID FOLDER"
End If
If Application.ActiveExplorer.Selection.Count = 0 Then
'Require that this procedure be called only when a message is
selected
Exit Sub
End If
For Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
If objItem.FlagStatus = olFlagComplete Then
objItem.FlagStatus = olFlagMarked
' objItem.FlagIcon = olPurpleFlagIcon
objItem.Move objFolder
objItem.FlagStatus = olFlagComplete
objItem.FlagIcon = olNoFlagIcon
Else
objItem.Move objFolder
End If
End If
End If
Next
Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub
Corey Thompson