Outlook VBA code to add date "yyyy mm dd" at the beginning of the subject line?

LaurenHancy

Board Regular
Joined
Aug 5, 2010
Messages
179
Good morning All!

Please may you help me. I am trying to add a date the email was sent/received into the subject line of emails using a macro on a bulk selected emails in a folder.

For Example "yyyy mm dd":

Is anybody able to help advise on this? Apologies, I am quite new to VBA coding.

Have a good day :)

L
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
So I did a search, and the code at this website will accomplish much of what you need (see halfway down the page), save that it only adds the current date to the front of the Subject line. This can be readily fixed by just changing the Date reference - and to make it formatted - use the following instead:
VBA Code:
Format(MItem.ReceivedTime,"YYYY MM DD")
You will then need to save the changes, so then in the following line, write: MItem.Save
Keep us updated on how you get on with this, and let me know if you have any questions.
 
Upvote 0
Hi Lauren - did you manage to get this to work?
 
Upvote 0
Hi Dan,

I was hoping for some assistance with an If statement.

sDate = Format(myItem.ReceivedTime, "yyyymmdd")
myItem.Subject
 
Upvote 0
Apologies.

Hi Dan,

I was hoping for some assistance with an If statement. I need to check to see if the subject starts with a Date, and if that date = format YYYYMMDD, do nothing otherwise add YYYYMMDD to start (as per below). I'm not sure if I should use IsDate or Instr, and I am struggling with a lack of knowledge.

sDate = Format(myItem.ReceivedTime, "yyyymmdd")
myItem.Subject = sDate & "[" & myItem.Sender & "] " & "[' myItem.Subject & "]"
myItem.Save

Thank you.
 
Upvote 0
Hi - happy to help, but you're best bet is to start a new thread. That way, other people will see that you'd like some help and can probably assist. Whereas, if you post something in reply to an existing thread, chances are that only Lauren and I will ever know about it :). I still have some work to finish today, but can take a look tomorrow if you don't hear from anyone else before then.
 
Upvote 0

Forum statistics

Threads
1,215,361
Messages
6,124,497
Members
449,166
Latest member
hokjock

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top