Wrong format of date entered within a macro in Writer

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
pansmanse
Posts: 29
Joined: Wed Nov 11, 2009 4:30 pm

Wrong format of date entered within a macro in Writer

Post by pansmanse »

I have a macro to create a letter head in Writer which inserts a date as a 'field-other' with a specified format (eg 18 November 2009).
When I open a new document and run the macro, the date format is lost, appearing as 40135.42 instead.
I have a work around (insert default format date, delete it and then insert the special format), which seems to work.
But is there a real solution?
Pansmanser
LO3.5.7.2/Ubuntu12.04
User avatar
acknak
Moderator
Posts: 22756
Joined: Mon Oct 08, 2007 1:25 am
Location: USA:NJ:E3

Re: Wrong format of date entered within a macro in Writer

Post by acknak »

[Moved to Macros and UNO API]
AOO4/LO5 • Linux • Fedora 23
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Wrong format of date entered within a macro in Writer

Post by JohnV »

I don't have a solution except to use a letterhead template like I do. The Date(fixed) field works fine there. New docs from template get the current date and then it remains fixed when they are reopened.
swordfish
Posts: 1
Joined: Thu Dec 03, 2009 12:16 am

Re: Wrong format of date entered within a macro in Writer

Post by swordfish »

I have only just started using openoffice. I am trying to create a letterhead with autodating, and the only date format I can include in my macro is of the form "2/12/09", whereas I want "2 December 2009", or "Wednesday 2 December 2009". Nothing I have done so far has succeeded. Is there a library of modules which would include something like this?
swordfish Ooo 3.1.1/windows vista
pansmanse
Posts: 29
Joined: Wed Nov 11, 2009 4:30 pm

Re: Wrong format of date entered within a macro in Writer

Post by pansmanse »

Swordfish, I have only just returned to this topic, and you may have solved your problem. Are you doing 'insert/field/date'? If you do 'insert/field/other/document/date' you have a choice of date formats.
Pansmanser
LO3.5.7.2/Ubuntu12.04
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Wrong format of date entered within a macro in Writer

Post by Villeroy »

pansmanse wrote:Swordfish, I have only just returned to this topic, and you may have solved your problem. Are you doing 'insert/field/date'? If you do 'insert/field/other/document/date' you have a choice of date formats.
Double-click an existing date field.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
kod65red
Posts: 8
Joined: Mon Jun 20, 2011 12:42 am

Re: Wrong format of date entered within a macro in Writer

Post by kod65red »

I have the same problem, except that I want to insert the date within the text of my documents, not in a letterhead. Doing "insert/field/other/document/date" allows me to insert a date of the format "19 June 2011" once; I want to set up a macro so I can do this quickly.

I've tried creating such a macro a few times, saving it in My Macros. It works well in the original document when I first create it; however, if I open another document or even save the first document, close it, and open it again, the macro malfunctions, producing a field like "40713.57" instead of a date. (When I rerecord the macro, I get slightly different numbers.) I've done similar things with a time macro and had the same problem. Any suggestions?
OpenOffice.org 4.1.1 on Windows 7 Home Premium
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Wrong format of date entered within a macro in Writer

Post by Villeroy »

40713.57 is the correct value. Formatted as date+time this number is equivalent to "2011-06-19 13:40:48"
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
kod65red
Posts: 8
Joined: Mon Jun 20, 2011 12:42 am

Re: Wrong format of date entered within a macro in Writer

Post by kod65red »

Ok ... then how do I get it to format as date+time? That's the point of the macro, to enter a date / time field that shows up in the format of our preference.
OpenOffice.org 4.1.1 on Windows 7 Home Premium
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Wrong format of date entered within a macro in Writer

Post by Villeroy »

Write a macro to format the number as date.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
kod65red
Posts: 8
Joined: Mon Jun 20, 2011 12:42 am

Re: Wrong format of date entered within a macro in Writer

Post by kod65red »

Ok. I'm sorry if I'm being dense or not explaining the problem fully enough. I just looked through the openoffice.org help files and don't really have a clue about how to do that or how it relates to the macro I already wrote.

Basically the macro I wrote was to automate what I was doing via 'insert/field/other/document/date' (since 'insert/field/date' was giving me the format '06/19/2011', which I don't want). I could do insert/field/other/document/date every time and it would work, but be slow. The point of the macro is to speed it up. If it's helpful I can post the code of the macro.
OpenOffice.org 4.1.1 on Windows 7 Home Premium
kod65red
Posts: 8
Joined: Mon Jun 20, 2011 12:42 am

Re: Wrong format of date entered within a macro in Writer

Post by kod65red »

I thought about it more, and I see what you mean by formatting the number as a date. I was able to format those numbers using right-click: format, but couldn't get that process to work as a macro. In any case, I think I more or less solved my problem using the following work-around: a default document template with a customized date and time at the top. Not too elegant, since the date and time now appear at the top of every new default document, and the macros don't work in old documents until I add a custom-formatted date. If anyone knows a more elegant solution, let me know. Thanks!
OpenOffice.org 4.1.1 on Windows 7 Home Premium
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Wrong format of date entered within a macro in Writer

Post by Villeroy »

The macro recorder does not record macros. It should be named "command recorder" since it records user interface actions more or less detailed.
If you can not program anything you can not write macros neither. The program is designed to be useful even when you don't know what a macro is.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
JohnV
Volunteer
Posts: 1585
Joined: Mon Oct 08, 2007 1:32 am
Location: Kentucky, USA

Re: Wrong format of date entered within a macro in Writer

Post by JohnV »

I suggest using an AutoText entry for this purpose (insert current date anywhere with desired format).
http://www.oooforum.org/forum/viewtopic.phtml?t=124595
pansmanse
Posts: 29
Joined: Wed Nov 11, 2009 4:30 pm

Re: Wrong format of date entered within a macro in Writer

Post by pansmanse »

kod56red.
I think my first post up there was one work around to your exact problem.
Pansmanser
LO3.5.7.2/Ubuntu12.04
Chalmers44
Posts: 9
Joined: Fri Nov 04, 2011 7:49 pm

Re: Wrong format of date entered within a macro in Writer

Post by Chalmers44 »

To John V:

Your Autotext answer looks wonderful, alas when I am NeoOffice writer and hit ctrl-F2 nothing happens.

Help!
NeoOffice 3.1.1 with MacOS X 10.6.6
User avatar
Hagar Delest
Moderator
Posts: 32653
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Wrong format of date entered within a macro in Writer

Post by Hagar Delest »

It may be because Ctrl+F2 is overridden by a desktop setting on Mac. In this case, use the menu Insert>Fields>Others.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Chalmers44
Posts: 9
Joined: Fri Nov 04, 2011 7:49 pm

Re: Wrong format of date entered within a macro in Writer

Post by Chalmers44 »

Preliminary questions.

- I can hit the check mark to add the additional format to my list of date formats (I want day month year) but the additional format never survives closing the file and reopening. What's up with that?

- You have written Cntrl-F3 but per my version of NeoOffice, it's Apple-F3 (How do I insert the apple character?)

- Why doesn't NeoOffice Help stay open when I am switching between it and my document?

- What is the difference between a shortcut key and a macro?

NOW, the main event. I enter the "shortcut key" but how do I "call" the shortcut key when I want it?

Here is what I have done:

In your document do Apple+F2
(OR Insert->Field->Option

> Document tab->Date->Date, then in Format select the one you like [or scroll down to the bottom of the formats and select 'Additional Formats'. Creat your own format, then click the Check Mark, which should put your format at the tom of the list of formats.] and click Insert. The text of the date should show up in your document. [It does!]

Now, in your Document If you would perhaps like the date centered then center it.

Now select the date field, do Apple+F3, (Edit->Autotext)


Click the + by your personal category (highlight 'My Autotext')


Enter a Name (“Date fluid”)

Change the suggested Shortcut key(s) [Shortcut Key suggested (Df), and how do I insert one, such as cntr-D??] if you want something else .

Then click the AutoText button and New.

Click Close and you’re done.

I HAVE DONE THIS, BUT HAVE NO IDEA HOW TO TRIGGER THE SHORTCUT KEY....
NeoOffice 3.1.1 with MacOS X 10.6.6
Post Reply