Ask Your Question
0

Basic Macro - Date NumberFormat [closed]

asked 2013-03-06 17:25:07 +0200

Morgen gravatar image

updated 2013-03-06 19:20:09 +0200

I am trying to insert the date into a letter as part of a larger macro. I would like to format by date "mmmm d, yyyy" (e.g. March 6, 2013). I have the following code which works perfectly except I don't know the NumberFormat for the desired date format.

Sub Main

Dim Doc As Object
Dim DateTimeField As Object
Dim Cursor As Object
Doc = ThisComponent
Cursor = Doc.Text.createTextCursor()

DateTimeField = Doc.createInstance("com.sun.star.text.textfield.DateTime")
DateTimeField.IsFixed = False
DateTimeField.IsDate = True
DateTimeField.NumberFormat = 84
Doc.Text.insertTextContent(Cursor, DateTimeField, False)

End Sub

The code "84" above will give the date in the ISO8601 format (learned from a random forum post) but not the format I want. The LibreOffice API website lists this optional property but gives no clue as to what the codes are, from what I can tell they are specific only to LibreOffice.

http://api.libreoffice.org/docs/common/ref/com/sun/star/text/textfield/DateTime.html

At this point I have scoured Google with absolutely no success, thanks for any help you can provide.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2015-10-26 21:57:59.744709

1 Answer

Sort by » oldest newest most voted
1

answered 2013-03-14 22:36:45 +0200

Morgen gravatar image

updated 2013-03-15 00:22:51 +0200

In the end I wrote a macro that printed all possible values from 1 to 6000. Here is the list of meaningful and unique NumberFormat values. Note some values are not date formats. If you would like the original file and macro, you will have to upvote my answer so I can get enough karma to upload files.

Macro run on March 14, 2013 at 2:29 pm.

10   =  4134761%
11   =  4134760.39%
20   =  $41,348
21   =  $41,347.60
24   =  41,347.61 USD
30   =  3/14/13
31   =  Thu 14/Mar 13
32   =  03/13
33   =  Mar 14
34   =  March
35   =  1st quarter 13
36   =  03/14/2013
38   =  Thursday, March 14, 2013
39   =  Mar 14, 13
40   =  14:29
41   =  14:29:38
42   =  02:29 PM
43   =  02:29:38 PM
44   =  992342:29:38
45   =  29:38.00
46   =  992342:29:38.00
50   =  03/14/13 02:30 PM
51   =  03/14/2013 14:30:00
60   =  4.13E+004
61   =  4.13E+04
70   =  41347 3/5
71   =  41347 26/43
72   =  41347 2/4
73   =  41347 60/100
75   =  Mar 14, 2013
76   =  March 14, 2013
77   =  Thu, Mar 14, 13
78   =  Thu, March 14, 2013
79   =  Thursday, March 14, 2013
80   =  14. Mar. 2013
81   =  14. March 2013
82   =  03-14
83   =  13-03-14
84   =  2013-03-14
99   =  TRUE
110  =  Thu Nissan 3 5773
111  =  Thu 3 Nissan 5773
112  =  3 Nissan 5773
113  =  Nissan 3 5773
114  =  3 Nissan
115  =  Nissan 3
116  =  Nissan 5773
117  =  Nissan
edit flag offensive delete link more

Comments

I needed this because the Record Macro function of insert with formatted date failed miserably. This saved my bacon. thanks.

OregonJohn gravatar imageOregonJohn ( 2016-04-21 02:18:35 +0200 )edit

Question Tools

Stats

Asked: 2013-03-06 17:25:07 +0200

Seen: 3,706 times

Last updated: Mar 15 '13