Frustrated with calculating future date

I'm trying to find a calculation that will show 14 days in the future from the date the word document is opened, every time.  Currently I am using

{QUOTE

{SET Delay 14}

{SET a{=INT((14-{DATE\@M})/12)}}

{SET b{={DATE\@yyyy}+4800-a}}

{SET c{={DATE\@M}+12*a-3}}

{SET d{Date\@d}}

{SET jd{=d+INT((153*c+2)/5)+365*b+INT(b/4)-INT(b/100)+INT(b/400)-32045+Delay}}

{SET e{={INT((4*(jd+32044)+3)/146097)}}

{SET f{=jd+32044-INT(146097*e/4)}}

{SET g{=INT((4*f+3)/1461)}}

{SET h{=f-INT(1461*g/4)}}

{SET i{=INT((5*h+2)/153)}}

{SET dd{=h-INT((153*i+2)/5)+1}}

{SET mm{=i+3-12*INT(i/10)}}

{SET yy{=10*e+g-4800+INT(i/10)}}

"{dd}-{mm}-{yy}"\@" MM/dd/yyyy"}

The problem I'm running into is the date will only be accurate the first time the document is opened, but if I try to run it the next day the date does not update.

Answer
Answer

Easier to put a { DOCVARIABLE varFutureDate } field in the document where you want the date to appear and then create an AutoOpen macro that contains the following code:

With ActiveDocument
    .Variables("varFutureDate").Value = Format(DateAdd("d", 14, Date), "MM/dd/yyyy")
    .Range.Fields.Update
End With

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Answer
Answer
Stefan Blom
Microsoft 365 Word MVP since 2005
Volunteer Moderator (Office)
MS 365, Win 11 Pro
~~~~
Please note that I do not work for Microsoft
MVP program info: https://mvp.microsoft.com/
~~~~

1 person found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 7, 2022 Views 515 Applies to: