Mac – How to create a macro in Outlook 2010 to add the the date to the subject line

macrosmicrosoft-outlookmicrosoft-outlook-2010vba

I am new to the VBA format of writing code and I have been researching how to get the current date to AUTO input into the Subject line of an email when commanded. I need to know how to complete the following task.

Subject line should read, "stuff stuff stuff TODAYS DATE"
Body should read, "Person, (return; tab) Stuff stuff stuff TODAYS DATE"

Also, if its possible I would like it to auto attach a file from a specific location that will have the name of "TODAYS DATE.xlsx"

Todays date should be in the format of DDMMMYY.

I am currently using a very basic macro to create the email and add the text where I need it.

Sub STUFF()
Dim msg As Outlook.MailItem
Set msg = Application.CreateItem(olMailItem)
msg.To = "EMAILS"
msg.CC = "EMAILS"
msg.Subject = "STUFF STUFF STUFF *DATE*"
msg.Body = "PERSON, STUFF STUFF STUFF *DATE*"
msg.Display
Set msg = Nothing
End Sub

Thanks for the help.

edit – For clarrification
I have tried the following:
Today's date in Outlook Mail Subject (2010/Quick Steps)
https://stackoverflow.com/questions/9177199/getting-the-current-date-in-visual-basic-2008
https://stackoverflow.com/questions/4313730/current-date-in-outlook-subject-line
And most of the other Google Results for any variation of the keywords "macro outlook 2010 current date"

edit 2 – Reason
My end goal is to have a Macro command, that when selected, creates a new email with the To, CC, Subject, Body, and Attachment completed for me so that I can just edit a couple lines of daily changing information and send it off. This will only be used when needed and not everytime I need to send a new email.

Best Answer

To accomplish the title of your post you are looking for Now with some date manipulation.

Sub STUFF()
    Dim msg As Outlook.MailItem
    Set msg = Application.CreateItem(olMailItem)
    msg.To = "email@email.ca"
    msg.CC = "BumblebeeJoe@email.ca"
    msg.Subject = "STUFF STUFF STUFF" & Now
    msg.Body = "PERSON, STUFF STUFF STUFF" & Now
    msg.Display
    msg.Attachments.Add ("e:\temp\" & Format(Now, "dd.mm.2014") & ".xlsx")
    Set msg = Nothing
End Sub

Now would just return the date which in our case is just appended to the strings for Subject and Body. If you are looking to format the date you would use something like Format(Now, "dd.mm.2014") that you see in the Attachment.Add example. More date formatting examples

As for the attachment that is fairly simple. I have not done any data validation for paths which you should do but I ended up with the following in my test. This also entirely depends on your file naming conventions.

enter image description here

Then all you would need to do is something like assign a quick access toolbar button to your macro.

Related Question