A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Moving mail items into an "Archive" folder



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 15th 06, 04:16 AM posted to microsoft.public.outlook.program_vba
Corey Thompson
external usenet poster
 
Posts: 2
Default Moving mail items into an "Archive" folder

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

  #2  
Old June 15th 06, 05:31 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default Moving mail items into an "Archive" folder

Am 14 Jun 2006 20:16:09 -0700 schrieb Corey Thompson:

You´re right, flagged completed messages can´t be moved.

First, for moving an item off the list you must use a backwards loop. Then,
the Move function returns the new object, use that and call its Save method
after changes.

BTW: What do you do if objFolder is Nothing? After the message box the code
goes on and will cause errors.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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

  #3  
Old June 15th 06, 12:46 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Moving mail items into an "Archive" folder

He can also use the Namespace.GetSharedDefaultFolder method to return the other user's Inbox, a bit easier than walking the folder tree.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Michael Bauer" wrote in message ...
Am 14 Jun 2006 20:16:09 -0700 schrieb Corey Thompson:

You´re right, flagged completed messages can´t be moved.

First, for moving an item off the list you must use a backwards loop. Then,
the Move function returns the new object, use that and call its Save method
after changes.

BTW: What do you do if objFolder is Nothing? After the message box the code
goes on and will cause errors.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


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

  #4  
Old June 16th 06, 03:02 PM posted to microsoft.public.outlook.program_vba
Corey Thompson
external usenet poster
 
Posts: 2
Default Moving mail items into an "Archive" folder

Thanks for the reply!

I'm not sure what a backwards loop is. You mean I should use something
other than a for each loop? Can I just call .save after the move?

Corey

Michael Bauer wrote:
Am 14 Jun 2006 20:16:09 -0700 schrieb Corey Thompson:

You´re right, flagged completed messages can´t be moved.

First, for moving an item off the list you must use a backwards loop. Then,
the Move function returns the new object, use that and call its Save method
after changes.

BTW: What do you do if objFolder is Nothing? After the message box the code
goes on and will cause errors.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


  #5  
Old June 17th 06, 09:58 AM posted to microsoft.public.outlook.program_vba
Michael Bauer
external usenet poster
 
Posts: 435
Default Moving mail items into an "Archive" folder

Am 16 Jun 2006 07:02:03 -0700 schrieb Corey Thompson:

Just copied from another thread, please replace the variable names by yours:

The loop starts with Items.Count and counts down to 1. (A For Each loops
from 1 to Count.)

intCount = objInbox.Items.Count
For i = intCount To 1 Step -1
Set objItem = objInbox.Items(i)
If objItem.Class = olMail Then
Set objMail = objItem


--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --


Thanks for the reply!

I'm not sure what a backwards loop is. You mean I should use something
other than a for each loop? Can I just call .save after the move?

Corey

Michael Bauer wrote:
Am 14 Jun 2006 20:16:09 -0700 schrieb Corey Thompson:

You´re right, flagged completed messages can´t be moved.

First, for moving an item off the list you must use a backwards loop.

Then,
the Move function returns the new object, use that and call its Save

method
after changes.

BTW: What do you do if objFolder is Nothing? After the message box the

code
goes on and will cause errors.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
-- www.VBOffice.net --

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I transfer items from my contacts folder to the "to:" list Riteesh Outlook - Using Contacts 3 May 9th 06 10:35 AM
"Sent Items" Folder Problem CWLee Outlook Express 6 May 8th 06 04:38 PM
Archiving mail items with a modified date of "none" Rich Cervenka Outlook - General Queries 0 March 25th 06 10:51 AM
moving "sent" letters to a new folder around messes everything up rock9995 Outlook Express 7 February 24th 06 08:49 PM
Purpose of "Delete Expired Items" in Outlook Auto-archive Window? Mark S. Outlook - Installation 1 January 17th 06 09:55 PM


All times are GMT +1. The time now is 03:54 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.