Create macro with non-standard date format

Hi, I’d like to create a macro in Writer to insert the current date with the format:
YYYY.MM.DD followed by two spaces underneath. Hence:

2020.01.02

The cursor should end up down here on this line where the text starts (At the beginning of the line). See?

Just for curiosity? Is there a reason to use the point here in place of the hyphen-minus as specified by the worldwide approved standard “ISO 8601 extended date format”?

Hello @WhiteBear, follow example file.

With Macro and Menu to trigger.

sub dddd
rem ----------------------------------------------------------------------
dim document, dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dim args1(5) as new com.sun.star.beans.PropertyValue
args1(0).Name = "Type"
args1(0).Value = 0
args1(1).Name = "SubType"
args1(1).Value = 0
args1(2).Name = "Name"
args1(2).Value = ""
args1(3).Name = "Content"
args1(3).Value = "0"
args1(4).Name = "Format"
args1(4).Value = 10107
args1(5).Name = "Separator"
args1(5).Value = " "
dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:WordLeftSel", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:Cut", "", 0, Array())
rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "SelectedFormat"
args3(0).Value = 1
dispatcher.executeDispatch(document, ".uno:ClipboardFormatItems", "", 0, args3())
dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:InsertPara", "", 0, Array())
end sub


Edit 06/04/2020

Sub InsertDateNow
dim args1(5) as new com.sun.star.beans.PropertyValue
args1(2).Name = "Text" : args1(2).Value = Format(Now(),"YYYY.MM.DD")
CreateUnoService("com.sun.star.frame.DispatchHelper") _
.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:InsertText", "", 0, args1())
End Sub

ATTENTION: If you would like to give more details to your question, use edit in question or add a comment below. Thank you.

If the answer met your need, please click on the ball Descrição da imagem to the left of the answer, to finish the question.

Thanks for the reply. Unfortunately it didn’t work. This is the output:

43834.91

See How to create a Macro to insert the current date in the current language for the proper way of using format IDs.