Macro for inserting current date as DD/MM/YYYY and after that add a text in LO Writer

I can’t find the info for writing a string with a custom format.
I’ve tried recording a macro and using a date field but didn’t work.
my macro inserts a date but the format is DD.MM.YYYY not DD/MM/YYYY, please help me:

sub addDateText
    dim document   as object
    dim dispatcher as object

    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("")

    dim sText as string
    sText = Format(Now(),"dd/mm/yyyy")

    dim textFormatat(0) as new
    textFormatat(0).Name = "Text"
    textFormatat(0).Value = sText+CHR$(9)+"[SomeText]"    
    dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, textFormatat())
end sub

Ceterum censeo…
Dates are very often expected to retain their original meaning anywhere in the world. Due to the funny stubbornness very few countries (but among them a big one) in the world are suffering from, unambiguousness cannot be achieved using the slash-formats without adding additional information.
The only internationally approved readable date format is YYYY-MM-DD (ISO 8601). This format is rich in advantages. Why not use it?

(and naturally sorting, I must add)

Hello adrian,
you could try:

sText = Format( Now, "DD\/MM\/YYYY")

Also see link

Thanks, I was accustomed to MsOffice VBA and i didn’t realize that / could be interpreted as special character.

I cannot confirm this.
Testing with LibO V5.3.1.1RC and also with V5.2.3.3 the code posted in the OQ (whether with format code in lower case or in upper case) worked flawlessly.
I would be happy to hear about the factual cause of the reported issue.

LibOffice: (x64).
Ok after reading your comment i’ve tried my original code but changed the document locale to en-US and worked. it produced the result i wanted ( 07/04/2017 [Some text] ) but if I change the locale of the document to other language than English (UK,US,Australia,Zimbabwe,…) it won’t work (as desired) even if i change the Date accepted patterns in Options->Language Settings->Languages so i think it’s a bug when you set lng. of the document other than EN

Hi, thanks for posting this solution. It works for me but with some slight problems. Firstly I dont need the words “SomeText” inserted. I tried deleting The part that says “[SomeText]”, which gets rid of that line, but then there’s an odd small box thingy that appears after the date. Also I’d like to insert two lines under the date if possible. Any help there?


Please do not post as an answer unless it actually is an answer to the question. Instead use add a comment or post as a new question.

Response to “Not-an-answer-question”:


textFormatat(0).Value = sText+CHR$(9)+"[SomeText]"

with this:

textFormatat(0).Value = sText+CHR$(10)+CHR$(10)+CHR$(10)