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 feature is built-in since a few years. The only thing remaining to do is to check or assign keyboard shortcut. There are two predefined functions.
Set:
Function | Keyboard |
---|---|
Insert Current Date | Ctrl + .. (dot) |
Insert Current Time | Shift + Ctrl + .. (dot) |
Menu Tools → Customize → Keyboard… → → insert →["Insert Current Date" | "Insert Current Time"]
Reference: forum.OOo
Original Outdated Text
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("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
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.