Insert current date as value to a cell in LibreOffice Calc

Estimated reading time of this article: 1 minute

How to insert the current date as value in LibreOffice Calc cell?

Inserting the current date is necessary for log entries. The date must not change afterwards.

This tiny LibreOffice Basic macro inserts the current date as string. The value is fixed. Put this function in a LibreOffice Basic module.

Inserting the string "NOW()" would update the date each time, i.e. the value is not fixed.

sub InsertCurDateValue
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("")

rem ----------------------------------------------------------------------
dim args1(0) as new
args1(0).Name = "StringName"
args1(0).Value = "" & Date

dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args1())

end sub

You can assign a key to the macro, e.g. F3.

How I created this macro?

I recorded it with the macro recorder using the NOW() function and replaced the NOW() string afterwards.