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



## LaurenHancy (Mar 24, 2021)

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


----------



## Dan_W (Mar 24, 2021)

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:   

```
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.


----------



## Dan_W (Apr 6, 2021)

Hi Lauren - did you manage to get this to work?


----------



## dts1234 (Feb 17, 2022)

Hi Dan,

I was hoping for some assistance with an If statement. 

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


----------



## dts1234 (Feb 17, 2022)

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.


----------



## Dan_W (Feb 18, 2022)

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.


----------



## dts1234 (Feb 18, 2022)

Thank you Dan. I will start a new thread.


----------

