• Current date plus x days macro

    Author
    Topic
    #2536233

    In Word, I know how to

    Insert => Date & Time

    but what I’d like to do is create a macro in a document in which the date always reflects a date 10 days from today. I would imagine this would require entering a function code, but when I open Date and Time, I only get the attached popup window, with no function code option. Thanks in advance for your advice!

    • This topic was modified 2 years, 2 months ago by t.o.m..
    Viewing 5 reply threads
    Author
    Replies
    • #2536268

      Graham Mayor has a method.
      http://www.gmayor.com/insert_a_date_other_than_today.htm

      cheers, Paul

      1 user thanked author for this post.
      • #2536335

        Thanks, Paul. I’ve never coded before. Where in Microsoft Word do I enter the recommended code?

    • #2536449

      I’ve no idea either – don’t have Word. Hopefully someone here will know.

      cheers, Paul

    • #2536481

      The article first shows modified Field coding, which for a novice to field coding seems daunting. After a Field is entered, Alt + F9 will toggle between the Field’s coding and the result of that coding that displays in the document.  The Field coding is entered thru the Edit Field window as a new Field code among the rest of the default Field codes.

      It is much easier to use the macro provided at the end of the article. I tried it and it works very well. Once engaged it opens a box to allow you to adjust the date offset to any number of days in the past or in the future. You can replace the 14 in the macro coding with 10 to change the default days from 14 to 10 so you just hit the Enter key when that box opens asking for how many days. You can also add that macro to your Quick Access toolbar or assign a keyboard shortcut for that macro.

      Let me know if you need help copying and pasting that macro to place in your Word documents.

      Thanks to Paul – I never seen that macro before. Good find!

      HTH, Dana:))

      • #2536878

        Thanks, Drcard. So I have that page with the macros up, but not sure what to do with it. Here’s the section of my Word document where I want the future date to appear…

           LOAN PAYOFF – FUTURE DATE

             Payoff balance, good until { DATE \@ “M/d/yyyy” }. TomC 6081

        When I right-click the date field, I get an option “Edit Field” and after I click that I get this popup window (screenshot attached) but I don’t know what to do next:

         

         

    • #2536903

      Fields and macros are totally different functions with different coding. Field coding is a lot more complicated than copying and pasting a macro. Even Graham said that the macro was much easier.
      Remove the field code (your{ DATE \@ “M/d/yyyy” }) from the document. At the place where you want this future date to appear place the cursor there and run the macro that will place that date there.
      The attached PDF gives you detailed instructions how to create your own macro from Graham Mayor’s coding as well as how to create an icon to run the macro or a custom keyboard shortcut to run the macro.
      I think you will find that using the macro will be a lot easier than using a field.

      Let me know if you need further info.  It make take a while for me to respond as traveling yields hit and miss on Internet connections.

      Easy-way-to-enter-a-copied-macro-into-your-Word-documents

      HTH, Dana:))

      • #2537884

        Thanks for that guidance. I successfully entered and ran the macro in a Word document, and it properly inserted a date 10 days future. But when I opened the document this morning, I saw that it does not automatically update. The macro appears to be limited to running a future-date calculation only the moment you insert it into your document. In other words, after you put it into your document, that future date remains fixed.

        Instead, I’m trying to get a macro that would work similarly to MS Word’s built-in date macro, which allows you to click a checkbox so that within your document, the macro each day automatically updates the date displayed to the current date. But instead of always displaying the current date, I want a 10-day future macro that is actually a continuously running, embedded formula in my Word document so that every day when I open the document, the date is always 10 days from the current date, rather than 10 days from the day I originally inserted the macro into the document.

        Is this even possible?

    • #2537951

      To see how to do this and just about everything else you might want to do with dates in Word (without the need for a macro), check out my Microsoft Word Date Calculation Tutorial, at:
      https://www.msofficeforums.com/word/38719-microsoft-word-date-calculation-tutorial.html
      or:
      http://www.gmayor.com/downloads.htm#Third_party
      In particular, look at the item titled Calculate a day, date, month and year, using n days delay. Do read the document’s introductory material.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      1 user thanked author for this post.
      • #2543389

        Thank you, macropod! I’m making progress… Using your item titled Calculate a day, date, month and year, using n days delay, I successfully created a 10-day future date. I reviewed and applied your date formatting change instructions in the document’s introduction, but for some reason the date format remains in extended European format. (It reads “Friday, 24 March 2023” instead of 3/24/2023.) Attached is a screenshot of my adjusted code, where you can see my attempt to change format.

    • #2545154

      Thanks for that guidance. I successfully entered and ran the macro in a Word document, and it properly inserted a date 10 days future. But when I opened the document this morning, I saw that it does not automatically update. The macro appears to be limited to running a future-date calculation only the moment you insert it into your document. In other words, after you put it into your document, that future date remains fixed.

      Sorry for the delay in responding, but I have been on a trip where Internet access was not available.
      You want the macro to run and enter the future date based upon the day that you use the form.
      This is easy to do. Since you have the macro that generates the correct date (10 days in the future), then all you need is MacroButton Field instead of a drop down list. The MacroButton with transparent display text can create a spot on your form to press to yield the future date into that form. When you use the form and double click the MacroButton it will run the macro and give the future date based on the day the MacroButton was clicked (the day you fill the form out). Thus the macro will calculate the correct future date when the form is used.

      The attached PDF instructions has the details on how to do this. Please ask if you have any questions.

      Create-Text-To-Run-a-Macro-In-Word

      HTH, Dana:))

    Viewing 5 reply threads
    Reply To: Current date plus x days macro

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: