Avatar of Justin Smith
Justin Smith
Flag for United Kingdom of Great Britain and Northern Ireland asked on

what is the syntax to show todays date in vb?

hi Guys, I have a macro which send out an email from in Excel and attaches a PDF. code is
.Attachments. Add "\\zebra\Report Template_20220215\Report_20220215.pdf"
How do tweak the dates in the code so it changes everyday ?  Is it needs to be Today -1 in this format ("YYYYMMDD")
Microsoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Justin Smith

8/22/2022 - Mon
Bembi

Format$(now() -1,"YYYYMMDD")
Now is a serial number which counts each da beginning at 01.01.1900, so if you substract 1 you get the date from yesterday.
This should deliver the date sequence you can add to your path / filename
Justin Smith

ASKER
what is the new code then?
.Attachments. Add ""\\zebra\Report Template_" & Format$(Now() - 1, "YYYYMMDD") & "\Report_" & Format$(Now() - 1, "YYYYMMDD" ?
Justin Smith

ASKER
do I have to Dim any variable?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Norie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Justin Smith

ASKER
I just run the path in the immediate window and it does not show the date at all. do I have to Dim strdate as date, string or something else?
Justin Smith

ASKER
in the immediate window it's showing the path as "\\zebra\Report Template_\Report
Justin Smith

ASKER
thanks very much for your help!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.