With the following code, “2025-09-01” was shown in message box,but the content in cell “a1” is “2025” , its CellContentType is value.
Sub WriteFormattedDateTime()
Dim oSheet As Object
Dim oCell As Object
Dim sFormattedDate As String
oSheet = ThisComponent.Sheets.getByName("Sheet1")
oCell = oSheet.getCellByPosition(0, 0)
sFormattedDate = Format(Now(), "YYYY-MM-DD")
msgbox sFormattedDate
oCell.value = sFormattedDate
End Sub
With the following code, “2025-09-01” was shown in message box,but the content in cell “a1” is “2025-09-01” , its CellContentType is text.
Sub WriteFormattedDateTime()
Dim oSheet As Object
Dim oCell As Object
Dim sFormattedDate As String
oSheet = ThisComponent.Sheets.getByName("Sheet1")
oCell = oSheet.getCellByPosition(0, 0)
sFormattedDate = Format(Now(), "YYYY-MM-DD")
msgbox sFormattedDate
oCell.string = sFormattedDate
End Sub
How can write whole date “2025-09-01” into cell and set CellContentType as value ?