'>>from here
' Author Jim Ward
' Creation 31st March 2004
'
' Description
'
' The following 2 routines allow the user to select a number of emails
' For each member of the selection prefix the subject with the received date and time
' in the format yyyymmdd_hhmm_<subject content>
'
' This allows for the messages to be filed outwith OUTLOOK as message files, when OUTLOOK
' saves these it uses the <SUBJECT> field for the filename. In introducing the date, we can
' now use the directory sort to get the messages in chronological order, without this the
' messages will be in the order of when they were saved to the drive, NOT the received date.
'
'
' The second routine takes a date stamped SUBJECT email and removes the date stamp.
'
' Modification History
' ====================
' Jim Ward
' 27th May 2004
' Added in logic to stop untagged subjects being unintentionally stripped of characters(1-14)
' checking that characters (1-8) are numeric and positions 9 and 14 are underscore
'
'
'
Sub PrefixSubjectWithDate()
'
' Declare variables
'
Dim myOlSel As Outlook.Selection
Dim olExp, olCurrentFolder
Dim X As Integer
'
' setup what we require
'
Set olExp = Outlook.ActiveExplorer
Set olCurrentFolder = olExp.CurrentFolder
Set myOlSel = olExp.Selection
'
' Process each message selected
' Modify the subject In the message, And save the changes
'
For X = 1 To myOlSel.count
thissubject = myOlSel.Item(X).Subject
thisdate = myOlSel.Item(X).ReceivedTime
newdate = Format(thisdate, "yyyymmdd_hhmm_")
myOlSel.Item(X).Subject = newdate & thissubject
myOlSel.Item(X).Save
Next X
End Sub
Sub UndoPrefixSubjectWithDate()
Dim myOlSel As Outlook.Selection
Dim olExp, olCurrentFolder
Dim X As Integer
Set olExp = Outlook.ActiveExplorer
Set olCurrentFolder = olExp.CurrentFolder
Set myOlSel = olExp.Selection
'
' modify the subject In the message, And save the changes
'
' Check that we have some resemblance to our date stamp string to stop users
' unwittingly removing untagged messages.
'
' We should have an underscore in positions 9 and 14 and
' numeric data in 1-8 and 10-13
'
For X = 1 To myOlSel.count
thissubject = myOlSel.Item(X).Subject
dash1 = InStr(1, thissubject, "_")
dash2 = 0
If dash1 = 9 Then
dash2 = InStr(dash1 + 1, thissubject, "_")
mytest = Mid(thissubject, dash1 + 1, 4)
If dash2 = 14 And IsNumeric(Left(thissubject, 8)) = True And IsNumeric(Mid(thissubject, dash + 1, 4)) = True Then
newSubject = Right(thissubject, Len(thissubject) - 14)
myOlSel.Item(X).Subject = newSubject
myOlSel.Item(X).Save
End If
End If
Next X
End Sub
'>>to here