Joined: May 02, 2009 Posts: 51 Location: Adelaide, South Australia
Posted: Thu May 20, 2010 4:21 am Post subject: Are 'global' macros for Date and Time fields possible?
Firstly, three cheers for the latest version NO, especially the drop-down menu for font selection - the latest font used is now clearly visible and easily accessible.
I've recently been having fun with macros and keyboard short-cuts … for entering dates and times in documents. However, it appears that the macros for these two fields only work for the document in which they were created. When I run them in a different document, either a new or and existing one, whether by keyboard short-cut or via Tools > Macros, a number (tonight it was 40318.85 - but it has varied) is produced in place of the expected result. The number is the same for each field.
Interestingly, the macro and keyboard short-cut I created for Format > Default Format works fine … I created it as, in the previous version of NO, the indicated keyboard short-cut for this operation was compromised by Mac OS X assignment).
So, do I have to rewrite the macro for every document I create or seek to modify? Or, is their some way of creating a 'global' macro for these functions? _________________ "His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
That sounds like a formatting issue to me - 40318.85 is 20:24 last night*, in how-many-days-since-the-last-day-of-1899-speke, which is what NeoOffice/OpenOffice/Excel use.
So the problem is the field needs formatting as a date field/cell - the data itself is correct.
*well, last night for you, anyway - it has yet to arrive here .
Incidentally, I can't help asking - does your screen name point to some kind of digital kosher smoked salmon entity? And should we be worshipping it?
Joined: May 02, 2009 Posts: 51 Location: Adelaide, South Australia
Posted: Thu May 20, 2010 7:00 pm Post subject:
Yoxi, I clearly do have a formatting issue when the macros for both Date AND Time return the same in [quote]how-many-days-since-the-last-day-of-1899-speke[/quote]. Not only that of course, but why do the macros only work in the document for which they were created?
What I didn't mention in my initial post, was my in efforts to overcome this situation, I modified my Default Template to include the macros, verified that they worked in the Untitled document associated with the exercise, but found that they didn't function as desired in new documents created from the template.
Ah yes, my nom de plume! Actually my 'screen name' here is a variation on my preferred (and original) appellation "GridLok", which I did initially use in this forum. But when, after having not visited these pages for a while, and changed my ISP, AND wiped out my Keychain, I found I could not resume using GridLok since any communication from Trinity/NeoOffice was inevitably sent to a defunct email address. Does it point to [i]some[/i] of [quote]digital kosher smoked salmon entity[/quote]? But of course! As for whether or not it should be worshipped that is entirely optional, although I assure you and all that inquire that it is most definitely in their best interests to do so. _________________ "His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
Yoxi, I clearly do have a formatting issue when the macros for both Date AND Time return the same in
Quote:
how-many-days-since-the-last-day-of-1899-speke
. Not only that of course, but why do the macros only work in the document for which they were created?
Macros can be created within a document. This is the default when creating a macro so that whomever else you send your document to will be able to use the macro.
Since you are using your macro as an input utility function, it makes sense to store your macro in your NeoOffice user preference files so that it is accessible to all documents. Note, however, that moving it to user preferences will mean that your macro will not be inserted into your documents so won't be able to link your macro to a button or form object.
To store a macro in your user preference files, do the following steps:
1. Open your existing macro, select all of the macro lines, copy them, and close the macro editing window.
2. Create a new macro with the copied macro lines but when NeoOffice asks you where you want to save the macro, ignore the default (which is a subfolder of the current document) and instead, save it under the My Macros :: Standard :: Module 1 folder.
3. To run the macro, select the macro from the My Macros :: Standard :: Module 1 folder in the Run Macro dialog.
Do the above steps make sense? If so, is your recreated macro accessible in all documents in that My Macros subfolder?
Joined: May 02, 2009 Posts: 51 Location: Adelaide, South Australia
Posted: Thu May 20, 2010 7:49 pm Post subject:
Thanks Pluby. Yes, that makes sense … and I already have the macros installed in the My Macros > Standard > Module 1 location, and they are available in all NO documents … new or old. BUT, only in those documents in which I actually created the macros for Date and Time, do they result in the current date and time. In all other documents both macros result in the 'coded' current time - whether entered 'long-hand' via menus or with the keyboard short-cuts I have established. _________________ "His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
Joined: May 02, 2009 Posts: 51 Location: Adelaide, South Australia
Posted: Fri May 21, 2010 5:35 am Post subject:
The macros seem to insert a field. I say this because whether the outcome is Date, Time, or current-time-expressed as a number string, they delete completely with a single keystroke; as opposed to text - in which characters are deleted one-at-a-time by single keystrokes.
Below are the macros for Insert Date & Insert Time:
sub InsertDate
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
sub InsertTime
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
Try changing the "Format" argument's value to "0" instead of "50XX". Although I find OpenOffice.org Basic syntax maddenly difficult to read, I read NeoOffice's underyling OpenOffice.org C++ code that sets the format in a new date or time field and in the format is zero, is uses Writer's default date format for date fields and HH:MM:SS format for time fields.
Does that change make your macro insert formatted date and time fields?
Joined: May 02, 2009 Posts: 51 Location: Adelaide, South Australia
Posted: Sat May 22, 2010 3:37 am Post subject:
Sure thing Pluby, that works … insofar as it gives Date in the format dd:mm:yy (default?) and, as you suggested Time as hh:mm:ss. I would very much prefer to have Date in the format yy:mm:dd and Time as hh:mm. Unfortunately I have absolutely no idea as to the underlying code. At this stage, I'll settle for creating a new macro for each document in which I want to enter the current date and time - as the documents concerned are journals, it will be a once-a-year task.
Perhaps the issue could be added to the wish-list of things to be done, when nobody has anything much to do (lol!!)
I wonder if it is also a problem with macros for other fields?
Thanks for your help … hopefully you (or someone) may yet think of a simple work-around. _________________ "His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
Once the date/time field is in the doc, right-click/ctrl-click on it, choose Fields from the contextual menu, and then you can edit the display format.
There should be a way to apply the desired valuefomat to the field in the macro, but I haven't found it yet.
Last edited by yoxi on Sat May 22, 2010 6:27 am; edited 1 time in total
Joined: Jun 20, 2006 Posts: 2051 Location: Midwest, USA
Posted: Sat May 22, 2010 6:12 am Post subject:
You might try asking at the macros forum at OpenOffice.org Community Forums, since this sounds like more of an OOo Basic issue and not a NeoOffice specific one. Those forums have several people skilled in writing macros; my guess is that someone there would have some suggestions.
I have found what is causing the problem and the problem is that this is a bug in NeoOffice's underlying OpenOffice.org 3.1.1 code. The OpenOffice.org bug is that if you have not yet manually inserted a date or time field in a document using the Insert :: Field menu, the Format codes in your macro will be ignored and you will get the unformatted timestamp.
Fortunately, there is a workaround for this OpenOffice.org bug. First, set the date format back to 5083 and the time format back to 5040 like you had ni your original macro. Then, before you use your macro for the first time in a particular document, insert a date field manually using the Insert :: Field :: Date menu. Delete this inserted field.
After you manually insert and delete a date field once in a Writer document, your macro should now work fine.
Joined: May 02, 2009 Posts: 51 Location: Adelaide, South Australia
Posted: Sun May 23, 2010 4:18 am Post subject:
Thanks for your interest and comments, yoxi and Lorinda.
Right on pluby! The suggested work-around works a treat. While, ideally, it would be great to have the bug fixed, I'm sure there are many more pressing matters … and not that many NO users that have my particular requirements. Meantime you have provided an eminently functional solution - much appreciated.
Er, pluby, guess what, that fix appears to only be good for the time that the particular document is open. I went through the exercise you suggested and, as I have indicated, it worked a treat. But! when I closed the document and then re-opened it, it was back to the time-stamp!
Since I will open and close a document many times in a year, I think it probably best if I re-establish the macro for each new document in which there will be an ongoing requirement for date and time fields - thus enabling use of the assigned keyboard shortcuts. For occasional use of date/time fields I'll stick with the menu-entry methods. _________________ "His hands were pure; but he had no hands"
Charles Peguy about Immanuel Kant.
Last edited by GridLox on Sun May 23, 2010 4:32 am; edited 1 time in total
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum