Ask Your Question
0

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 +0100

adrian.georgescu gravatar image

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

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("com.sun.star.frame.DispatchHelper")

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

    dim textFormatat(0) as new com.sun.star.beans.PropertyValue
    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

Comments

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 +0100 )edit

(and naturally sorting, I must add)

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

1 Answer

Sort by » oldest newest most voted
0

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

librebel gravatar image

Hello adrian, you could try:

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

Also see link

edit flag offensive delete link more

Comments

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 +0100 )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 +0100 )edit

@Lupp. LibOffice: 5.3.0.3 (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 +0100 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 1,686 times

Last updated: Mar 14 '17