Reputation: 107
I use a macro in outlook 2003 to move selected emails to a specific folder. The moving works, but unfortunately the received date is overwritten to the current time. Any idea on how to prevent this.
I use this code:
Sub verschiebenInOrdner()
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 = objNS.Folders.Item("2009").Folders.Item("In")
If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly + vbExclamation, "INVALID FOLDER"
End If
If Application.ActiveExplorer.Selection.Count = 0 Then
Exit Sub
End If
For Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
objItem.UnRead = False
objItem.Move objFolder
End If
End If
Next
Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing
End Sub
Thanks to the help of 76mel I came up with this:
Sub verschiebenInArchiv()
Dim Session As Redemption.rDOSession
Dim objFolder As Redemption.RDOFolder
Dim objItem As Outlook.MailItem
Dim objItem2 As Redemption.RDOMail
Set Session = CreateObject("Redemption.RDOSession")
Session.Logon
Set objFolder = Session.Stores.Item("2009").IPMRootFolder.Folders("In")
If Application.ActiveExplorer.Selection.Count = 0 Then
Exit Sub
End If
For Each objItem In Application.ActiveExplorer.Selection
Set objItem2 = Session.GetMessageFromID(objItem.EntryID, Session.Stores.DefaultStore.EntryID)
objItem2.Move objFolder
Next
End Sub
This works when I am in my Inbox. Does anybody know how I can set the Store-ID in GetMessageFromID to the ID of the store in which my selection is made?
Edit: Thanks 76mel, I am using objItem.Parent.StoreID now to get the current StoreID.
Upvotes: 1
Views: 3036
Reputation: 1
I found the solution : in the sub folder you move the email to, simply add a column for the field "date created" instead of "received date" and sort using this field... job done !
Reef
Upvotes: 0
Reputation: 4043
Your right there has been a few reports around the net saying it doesn’t work.
It would seem that VB6 doesn’t bubble up an error :( . I think that the way to tackle this would be to use CDO or the defacto 3rd party lib "Redemption". To do the actual move in the background.
M
Update: Try something like this .. I dont have VB on may machine so haven't tested it But you will get the idea.
Sub verschiebenInOrdner()
On Error Resume Next
Dim objNS As Outlook.NameSpace
Dim objRDOSession As Redemption.RDOSession
Dim objRDOFolder As Redemption.RDOFolder
Dim objItem As Outlook.MailItem
Dim objRDOMail As Redemption.RDOMail
Set objNS = Application.GetNamespace("MAPI")
Set objRDOSession = CreateObject("Redemption.RDOSession")
objRDOSession.MAPIOBJECT = objNS.MAPIOBJECT 'or Logon
Set objRDOFolder = Session.GetFolderFromPath("<YOUR PATH>")
' do your validation for folder and selection
For Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
Set objRDOMail = objRDOSession.GetMessageFromID(objItem.EntryID)
objRDOMail.UnRead = False
objRDOMail.Move objRDOFolder
End If
End If
Next
Set objItem = Nothing
Set objRDOMail = Nothing
Set objRDOFolder = Nothing
Set objRDOSession = Nothing
Set objNS = Nothing
End Sub
Upvotes: 1
Reputation: 2338
It doesn't change the date for me in Outlook 2003 either. If it is a continuing problem for you I would try to get the date of the item and overwrite it after transferring it.
Upvotes: 0