Newbie needs help with Outlook Macro

Status
Not open for further replies.

chrisk2305

Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Hi Guys,

My Goal is create a Outlook Macro that adds the date into the subject line of every email for the following occasions:
Every email that arrives
Every new Email I create
Every Email I answer or forward

The Subject should look like: "2016-05-11 This is a test"

My first try was to create a script rule for incoming emails. The script contains the following code:

Code:
Sub ChangeSubject()
Dim myolApp As Outlook.Application
Dim aItem As Object

Set myolApp = CreateObject("Outlook.Application")
Set mail = myolApp.ActiveExplorer.CurrentFolder

For Each aItem In mail.Items
      aItem.Subject = "Date" & aItem.Subject
    aItem.Save
    
 
Next aItem
End Sub
The code was actually copied from this side. But actually nothing happens and I have no idea how to debug. Can you guys help a noob? :)

Thanks in advance!
Christian
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It works on the selected folder, but is not what you want - it adds Date to the subject line:
DateOutlook Tip for May 9 2016

I'm assuming you want something more like this;
5/11/2016 Outlook Tip for May 9

which is set by this:
aItem.Subject = Date & " " & aItem.Subject
Date = today's date - if you want the received date:
2016-05-09 Outlook Tip for May 9 2016
use
aItem.Subject = Format(aItem.ReceivedTime, "yyyy-mm-dd") & " " & aItem.Subject

But... this macro is one you need to manually run. If you do that, you need to check the messages to see if the date was already added, otherwise, you'll add it to every message in the folder.

If you want it done automatically, you need an itemadd macro.
How to use an ItemAdd Macro


There is an itemsend mail here - Add a keyword to the subject of all messages sent - that can be tweaked to add the date.
 

chrisk2305

Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
alright, got everthing working so far. But i have one question: How is it possible to answer an email that already has the date in the subject and replace it with date of answering event and also to replace an exisiting date upon receiving with the current date. I hope I could make clear what I want to achieve. Thanks in advance!
 
Status
Not open for further replies.
Top