Search code examples
libreofficelibreoffice-basic

Libre office writer macro insert date, and date + n days


There is a similar question here but using calc however teh answer woul seem to be calc specific. I would like to write a macro in libre writer that inserts the current date, a comma and space then the current date + 2 days, a comma and space then the current date + 14 days.

Recording a marco of date insertion gives the following however to be honest i dont have a clue how to interpret this code and can find little help on the net.

sub recall_period
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:InsertDateField", "", 0, Array())


end sub

Would appreciate any helps or ides. Cheers Damian


Solution

  • Andrew Pitonyak's macro document has a number of examples of working with dates.

    • Section 7.7.1 shows an example of inserting a date field into a Writer document.
    • Section 7.7.2 also shows how to add 10 days to a date.
    • Listing 5.100 gives a function to add any amount to a date.
    • Section 6.7 shows examples of using Now() to get the current date.

    Note: Recording a macro is usually not a good way to learn Basic programming, because it records ugly dispatcher calls rather than more elegant API code.