T
Thomas
Hy everybodey,
I wrote a pieve of code to move emails from one .pstn folder to anothor one.
Not difficult, but unfortunately the Date appears to be changed after the
move. It appears that after applying the move method the ReceivedTime
property shows the time of the move, rather than the time when the email was
received.
Simply overwriting the faulty time afterwards does not work either, because
ReceivedTime is write-protected for MailItem.
Does anybody know a workaround or are there some bugs in the piece of code I
attach?
Sub Move_to_old_pst()
Dim s As String 'For Debug message
Dim found As Boolean
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myNewFolder, myOldFolder, myNewSubFolder, myOldSubFolder As
Outlook.MAPIFolder
Dim myItem, myItem2, myItem3 As Object
Set myNameSpace = myOlApp.GetNamespace("MAPI")
' put in some existing opened .pst folders here, which are not harmed by
playing around
' Mailes are assumed to be in subfolders of the same name in both .pst folders
Set myNewFolder = myNameSpace.Folders("xx new")
Set myOldFolder = myNameSpace.Folders("xx")
GoSub MoveRoutine
Exit Sub
MoveRoutine:
For Each myNewSubFolder In myNewFolder.Folders
found = False
For Each myOldSubFolder In myOldFolder.Folders
If myOldSubFolder.Name = myNewSubFolder.Name Then
found = True
Exit For
End If
Next
If Not found Then
myOldFolder.Folders.Add (myNewSubFolder.Name)
Set myOldSubFolder = myOldFolder.Folders(myNewSubFolder.Name)
End If
' For debugging
s = myNewSubFolder.Name & vbCrLf & vbCrLf
For Each myItem In myNewSubFolder.Items
' For debugging: Original receive time
s = s & myItem.Subject & vbCrLf & myItem.ReceivedTime & vbCrLf
' >>> Here is the problematic move <<<<<
myItem.Move myOldSubFolder
' For debugging: Still Original receive time
s = s & myItem.ReceivedTime & vbCrLf
' For debugging only: Time of Move as receive time
Set myItem2 = myOldSubFolder.Items(myItem.Subject)
s = s & myItem2.ReceivedTime & vbCrLf
MsgBox s
Exit Sub
Next
Return
End Sub
I wrote a pieve of code to move emails from one .pstn folder to anothor one.
Not difficult, but unfortunately the Date appears to be changed after the
move. It appears that after applying the move method the ReceivedTime
property shows the time of the move, rather than the time when the email was
received.
Simply overwriting the faulty time afterwards does not work either, because
ReceivedTime is write-protected for MailItem.
Does anybody know a workaround or are there some bugs in the piece of code I
attach?
Sub Move_to_old_pst()
Dim s As String 'For Debug message
Dim found As Boolean
Dim myOlApp As New Outlook.Application
Dim myNameSpace As Outlook.NameSpace
Dim myNewFolder, myOldFolder, myNewSubFolder, myOldSubFolder As
Outlook.MAPIFolder
Dim myItem, myItem2, myItem3 As Object
Set myNameSpace = myOlApp.GetNamespace("MAPI")
' put in some existing opened .pst folders here, which are not harmed by
playing around
' Mailes are assumed to be in subfolders of the same name in both .pst folders
Set myNewFolder = myNameSpace.Folders("xx new")
Set myOldFolder = myNameSpace.Folders("xx")
GoSub MoveRoutine
Exit Sub
MoveRoutine:
For Each myNewSubFolder In myNewFolder.Folders
found = False
For Each myOldSubFolder In myOldFolder.Folders
If myOldSubFolder.Name = myNewSubFolder.Name Then
found = True
Exit For
End If
Next
If Not found Then
myOldFolder.Folders.Add (myNewSubFolder.Name)
Set myOldSubFolder = myOldFolder.Folders(myNewSubFolder.Name)
End If
' For debugging
s = myNewSubFolder.Name & vbCrLf & vbCrLf
For Each myItem In myNewSubFolder.Items
' For debugging: Original receive time
s = s & myItem.Subject & vbCrLf & myItem.ReceivedTime & vbCrLf
' >>> Here is the problematic move <<<<<
myItem.Move myOldSubFolder
' For debugging: Still Original receive time
s = s & myItem.ReceivedTime & vbCrLf
' For debugging only: Time of Move as receive time
Set myItem2 = myOldSubFolder.Items(myItem.Subject)
s = s & myItem2.ReceivedTime & vbCrLf
MsgBox s
Exit Sub
Next
Return
End Sub