Libre writer macro for date fails here’s the fix

When I used Libre Writer Record Macro to put the date in as a non-fixed field it would, after saving as a template then opening the template, put the date field in as a number instead of formatted mmm d, yyyy. Very frustrating, tried over and over again.

Found answer thanks to this guys work

https://ask.libreoffice.org/en/question/13945/basic-macro-date-numberformat/

I changed his function NumberFormat from 84 to 76 so I got my mmm d, yyyy format. He also made a chart of the possible formats (see below)

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 = 76
Doc.Text.insertTextContent(Cursor, DateTimeField, False)

End Sub

Here’s the list of numbers and formats

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