Auto-incrementing a date field value by 1 on each page of a Writer document?

I am trying to create a yearly diary in Writer, with one page per day. I want a field at the top of each page formatted like “Friday, 31 December 1999”.

Is there any way I could run a macro that would insert a copy of the first page and increment this field at the same time?

(I don’t mind hitting a hotkey 365 times to execute the macro!)

So, you will print the empty pages (to write them later) only with the date?

Maybe you can create a Form Letter (aka mail merge). The dates list can be created in Calc.

1 Like

There is no need of a macro for that. Use a user-defined variable.

  1. At the point where you start your agenda, define the initial value of the variable:
    1. Insert>Field>More Fields, Variables tab
    2. Type: Set Variable, Name: thedate (this is only an example for the name), Format: Additional formats and choose one of your liking in Date
    3. Value: this is tricky to set because it is the number of days since the epoch (1900-01-01)
      Roughly, multiply the number of years by 365.25 display the result and adjust to exact date. E.g. today is 2022-12-20 and the corresponding number is 44915.
  2. To display the next day:
    1. Insert>Field>More Fields, Variables tab
    2. Type: Set Variable, Select: thedate (the name you defined above), Format: Additional formats and choose one of your liking in Date
    3. Value: thedate+1
      You can also increment by another factor: 2 for every other date or 7 for each week; if you have a huge gap, you can also compute the exact number as in the first step to restart a sequence (this may be safer maintenance-wise if you slice your agenda into “chapters”).

Due to a present limitation in Writer (see bug tdf#128041), you can’t insert directly your variable in the page header (it will show the same value everywhere). But there is a workaround.

The date is probably a paragraph on its own in your document. Assign it a Heading n style. Choose the “n” consistently with your structure. It can be 1 if you have no chapters. If your dates are within a chapter (itself at level 1), choose “2”, etc.

  1. In the header, Insert>Field>More Fields, Document tab
  2. Type: Chapter, Format: Chapter name, Level: the one you chose for the date

It will show in the header the date of the first paragraph in the page. Symmetrically, you can insert the same field in the footer to show the date of the last paragraph in the page.

In case you want only one date per page, modify the Heading n (the one used to format the dates) Text Flow tab to automatically insert a page break before the date.

2 Likes

Thanks ajlittoz, I finally got around to trying this out - worked a treat!