I want to automatically insert today's date in a cell, but I don't want it to change in the future. How can I best do that?
Regards,
Nocton
[Solved] Insert today's date as a static date
[Solved] Insert today's date as a static date
Last edited by RoryOF on Mon Mar 31, 2014 9:39 am, edited 2 times in total.
Reason: Added green tick [RoryOF, Moderator]
Reason: Added green tick [RoryOF, Moderator]
OpenOffice 4.1.12 on Windows 10
-
- Volunteer
- Posts: 1160
- Joined: Mon Oct 08, 2007 1:26 am
- Location: France, Paris area
Re: Insert today's date as a static date
Bernard
OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
OpenOffice.org 1.1.5 / Apache OpenOffice 4.1.1 / LibreOffice 5.0.5
MS-Windows 7 Home SP1
Re: Insert today's date as a static date
Thank you for pointing me to Villeroy's solution. So I ended up with:
Very important to allow iterations [Tools>Options>Calc>Calcultation: Enable iterations.] as I had something similar but always got an error.
Regards,
Nocton
Code: Select all
=IF(A1="";"";IF(B1="";TODAY();B1))
Regards,
Nocton
OpenOffice 4.1.12 on Windows 10
Re: [Solved] Insert today's date as a static date
Macro solutions:
Code: Select all
Sub SetTodayDateToSelectedCellAsLocalizedFormula
rem The target cell will be formatted based on the local settings of the date
Dim oCell As Object
Dim DateStr as string
DateStr = Date(DateValue(Now))
oCell = ThisComponent.getCurrentSelection()
oCell.FormulaLocal = DateStr
End sub
Sub SetTodayDateToSelectedCellAsValue
rem In this case You need format the cell manually
Dim oCell As Object
oCell = ThisComponent.getCurrentSelection()
oCell.setValue(DateValue(Now))
End sub
Sub SetTodayDateToSelectedCellAsFormattedString
rem The date "value" will be formatted as String (You can not use that string for calculations directly)
Dim oCell As Object
Dim DateStr as string
DateStr = (Format(DateValue(Now),"YYYY-MM-DD"))
oCell = ThisComponent.getCurrentSelection()
oCell.String = DateStr
End sub
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
-
- Posts: 4
- Joined: Fri Mar 12, 2021 11:31 pm
Re: [Solved] Insert today's date as a static date
Hi,
How would I make that macro aply to a specific cell?
Thank you
How would I make that macro aply to a specific cell?
Thank you
Zizi64 wrote:Macro solutions:
Sub SetTodayDateToSelectedCellAsValue
rem In this case You need format the cell manually
Dim oCell As Object
oCell = ThisComponent.getCurrentSelection()
oCell.setValue(DateValue(Now))
End sub
OpenOffice 4.1.7 on Windows 10