Hi all,
A complete Outlook macro newbie here (and a macro newbie in general). I have been trying to get a macro to work to add a date/time stamp to the subject of all emails in the selected outlook folder. I am receiving an error on my 'check' line to avoid duplication of the date/time stamp on emails that the macro has already ran on. The below is my macro. it works as planned, except for the If formula to decide to skip an email or not. Any help resolving this issue would be GREATLY appreciated.
Sub AddFileName2()
Dim myolApp As Outlook.Application
Dim aItem As Object
Set myolApp = CreateObject("Outlook.Application")
Set mail = myolApp.ActiveExplorer.CurrentFolder
Dim iItemsUpdated As Integer
Dim strTemp As String
Dim strFilenum As String
iItemsUpdated = 0
For Each aItem In mail.Items
strTemp = aItem.ReceivedTime & " " & aItem.Subject
If Left(aItem, 8) = Left(aItem.ReceivedTime, 8) Then GoTo Skip
aItem.Subject = strTemp
iItemsUpdated = iItemsUpdated + 1
aItem.Save
Skip:
Next aItem
MsgBox iItemsUpdated & " of " & mail.Items.Count & " Messages Updated"
Set myolApp = Nothing
End Sub
Additionally, if anyone is interested in bonus points, I had to add in this check after I duplicated the macro and therefore the date/time stamp on some emails. If there's an easy variation to have another macro to remove the date/time stamp form the subject line, that would also be a huge help.
Thank you in advance!
A complete Outlook macro newbie here (and a macro newbie in general). I have been trying to get a macro to work to add a date/time stamp to the subject of all emails in the selected outlook folder. I am receiving an error on my 'check' line to avoid duplication of the date/time stamp on emails that the macro has already ran on. The below is my macro. it works as planned, except for the If formula to decide to skip an email or not. Any help resolving this issue would be GREATLY appreciated.
Sub AddFileName2()
Dim myolApp As Outlook.Application
Dim aItem As Object
Set myolApp = CreateObject("Outlook.Application")
Set mail = myolApp.ActiveExplorer.CurrentFolder
Dim iItemsUpdated As Integer
Dim strTemp As String
Dim strFilenum As String
iItemsUpdated = 0
For Each aItem In mail.Items
strTemp = aItem.ReceivedTime & " " & aItem.Subject
If Left(aItem, 8) = Left(aItem.ReceivedTime, 8) Then GoTo Skip
aItem.Subject = strTemp
iItemsUpdated = iItemsUpdated + 1
aItem.Save
Skip:
Next aItem
MsgBox iItemsUpdated & " of " & mail.Items.Count & " Messages Updated"
Set myolApp = Nothing
End Sub
Additionally, if anyone is interested in bonus points, I had to add in this check after I duplicated the macro and therefore the date/time stamp on some emails. If there's an easy variation to have another macro to remove the date/time stamp form the subject line, that would also be a huge help.
Thank you in advance!