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