I'm going to show you how to send email with an attachment and add a date to
that attachment this was brought up to me the other day oh now it's important
to keep track of when invoices and statements were sent I'll include the
code with this video this is what the result is is you have your email address
sent and there's a subject and your file name whatever would be and we've just
added the date today's date in on the end of this attachment so let's go
through this um so here you can see on sheet1 that I have email addresses in
column a I have subjects in column B and I have the name of the attachment and
column C now if we bring up our my folder where I have where I have these
attachments you can see that I have the name of the attachment is actually brown
I've gonna need them color is brown green and orange but I've named them
explain what I've done first of all we declare all our values here we say e
address subject message and note I have I've declared file name and new file
name both us strings I declared Outlook as an object Outlook mail is an object
my attachment is an object path that's password this file is located as a
string attachment as a string and X is an integer and so I've got a do-while
loop here and I'm saying do-while column a column a is not blank so as long as
there's email addresses in column a then you're gonna go looping through this so
I set outlook app and create objects Outlook mail outlook item set outlook
create item my attachments outlook items dot attachments path so this I've shown
you before you just right-click in the address bar of wherever your files are
located then you can copy the path here please note you have
the ending backslash address is what we have in cells in the a column subject is
whatever we have in the B column now the file name
I have sheet name and I have a color so the first one is brown and then I say
new file name here this is where we need we name our file to add the date so I
say new file name equals underscore format and I'm telling it how to format
the date and then I'm saying and then add a PDF to this this word here now
then this is the name function which is name then you include the path and the
filename and then you say as and then you're gonna say to new file name but so
here we have path and filename and now I've included add dot PDF so that it can
find the file name because if I just put the file name in without the extensional
you'll tell me it cannot be found and and then I say as and then I include the
path again and then the new file name so the file will be renamed and now we do
and then we do attachment equals path plus new file name and we go Outlook
mail equals e address and then we Carbon Copy is nothing blind carbon copy is
nothing and subject is our what we have in column B and then I say please find
your statement attached and best regards and then I say my attachment add Outlook
mail display and address equals nothing and then you go plus X plus 1 and then
we'll get our loop going so let's f8 through this code and see
how it works so we're cooking wind along here we've set my packing too on my
desktop and ie addresses the fur is in column a and subject is in column B and
final name the first half the file name is in in column C and then I'm going on
to renaming this file so let me scroll up a bit so you can see it so new file
name equals underscore file name and the date plus PDF and then I go that
I'm saying new file name this is how to find the new file or the old file and
then I'm saying this this is call it a new file and attachment equals path a
new file name Outlook is equals email address and then the Carbon Copy and the
subject and then please find an attachment okay
and we'll display it in here again we have our our our attachment with the
date added to it please note that when you go back to the file folder your file
your file in your file folder is now going to be renamed with the date on it
so then that way you're able to track when this invoice or statement was sent
so that is how you add an attachment and you added a date to the attachment
please subscribe