Ask Your Question

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

asked 2017-03-14 09:55:21 +0200

adrian.georgescu gravatar image

updated 2017-03-14 09:55:52 +0200

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
edit retag flag offensive close merge delete


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?

Lupp gravatar imageLupp ( 2017-03-14 12:13:28 +0200 )edit

(and naturally sorting, I must add)

Mike Kaganski gravatar imageMike Kaganski ( 2017-03-14 12:20:18 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-03-14 11:39:38 +0200

librebel gravatar image

Hello adrian, you could try:

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

Also see link

edit flag offensive delete link more


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

adrian.georgescu gravatar imageadrian.georgescu ( 2017-03-14 12:01:17 +0200 )edit

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.

Lupp gravatar imageLupp ( 2017-03-14 13:58:29 +0200 )edit

@Lupp. 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

adrian.georgescu gravatar imageadrian.georgescu ( 2017-04-07 11:30:00 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-03-14 09:55:21 +0200

Seen: 1,921 times

Last updated: Mar 14 '17