Date format macro.

classic Classic list List threaded Threaded
14 messages Options
rhubarbpieguy rhubarbpieguy
Reply | Threaded
Open this post in threaded view
|

Date format macro.


I'd like to create a macro for a user-defined date format (H:MMa/p).  As
examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p.  I can
create the format manually, but I understand the LibreOffice format
can't save user-defined formats.  So my thought is to create a macro
which creates the format each time the spreadsheet is opened.  The
user-defined Format Code is for a saved Style.

The macro records without incident and the date format is correct.
However, running the saved macro doesn't change the format.  It seems
this should work.  Thoughts?  The recorded macro is as follows:

sub FormatTime
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")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$D$13"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "DesignerDialog"
args2(0).Value = true

dispatcher.executeDispatch(document, ".uno:DesignerDialog", "", 0, args2())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:EditStyle", "", 0, Array())

rem ----------------------------------------------------------------------
dim args4(0) as new com.sun.star.beans.PropertyValue
args4(0).Name = "DesignerDialog"
args4(0).Value = false

dispatcher.executeDispatch(document, ".uno:DesignerDialog", "", 0, args4())


end sub





--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Dave Barton Dave Barton
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

-------- Original Message  --------
From: [hidden email]
To: [hidden email]
Date: Thu, 19 Jul 2012 16:48:53 -0500

>
> I'd like to create a macro for a user-defined date format (H:MMa/p).  As
> examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p.  I can
> create the format manually, but I understand the LibreOffice format
> can't save user-defined formats.  So my thought is to create a macro
> which creates the format each time the spreadsheet is opened.  The
> user-defined Format Code is for a saved Style.
>
> The macro records without incident and the date format is correct.
> However, running the saved macro doesn't change the format.  It seems
> this should work.  Thoughts?  The recorded macro is as follows:
>
> sub FormatTime
> 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")
>
> rem ----------------------------------------------------------------------
> dim args1(0) as new com.sun.star.beans.PropertyValue
> args1(0).Name = "ToPoint"
> args1(0).Value = "$D$13"
>
> dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
>
> rem ----------------------------------------------------------------------
> dim args2(0) as new com.sun.star.beans.PropertyValue
> args2(0).Name = "DesignerDialog"
> args2(0).Value = true
>
> dispatcher.executeDispatch(document, ".uno:DesignerDialog", "", 0, args2())
>
> rem ----------------------------------------------------------------------
> rem dispatcher.executeDispatch(document, ".uno:EditStyle", "", 0, Array())
>
> rem ----------------------------------------------------------------------
> dim args4(0) as new com.sun.star.beans.PropertyValue
> args4(0).Name = "DesignerDialog"
> args4(0).Value = false
>
> dispatcher.executeDispatch(document, ".uno:DesignerDialog", "", 0, args4())
>
>
> end sub

Sorry I can't help with your macro, but I like your idea.
An alternative approach I use, is to add my user defined date format to
my Calc default template.

Dave


--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Andreas Säger Andreas Säger
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

In reply to this post by rhubarbpieguy
Am 19.07.2012 23:48, [hidden email] wrote:
  but I understand the LibreOffice format
> can't save user-defined formats.

The entire suite is about customization rather than programming.
Templates and styles provide most of the productivity features. Macros
(particularly recorded ones) are a total waste of time.


--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

rhubarbpieguy rhubarbpieguy
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

In reply to this post by Dave Barton
On 07/20/12 02:16, Dave Barton wrote:

> -------- Original Message  --------
> From: [hidden email]
> To: [hidden email]
> Date: Thu, 19 Jul 2012 16:48:53 -0500
>
>> I'd like to create a macro for a user-defined date format (H:MMa/p).  As
>> examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p.  I can
>> create the format manually, but I understand the LibreOffice format
>> can't save user-defined formats.  So my thought is to create a macro
>> which creates the format each time the spreadsheet is opened.  The
>> user-defined Format Code is for a saved Style.
>>
>> The macro records without incident and the date format is correct.
>> However, running the saved macro doesn't change the format.  It seems
>> this should work.  Thoughts?  The recorded macro is as follows:
>>
>> sub FormatTime
>> 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")
>>
>> rem ----------------------------------------------------------------------
>> dim args1(0) as new com.sun.star.beans.PropertyValue
>> args1(0).Name = "ToPoint"
>> args1(0).Value = "$D$13"
>>
>> dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
>>
>> rem ----------------------------------------------------------------------
>> dim args2(0) as new com.sun.star.beans.PropertyValue
>> args2(0).Name = "DesignerDialog"
>> args2(0).Value = true
>>
>> dispatcher.executeDispatch(document, ".uno:DesignerDialog", "", 0, args2())
>>
>> rem ----------------------------------------------------------------------
>> rem dispatcher.executeDispatch(document, ".uno:EditStyle", "", 0, Array())
>>
>> rem ----------------------------------------------------------------------
>> dim args4(0) as new com.sun.star.beans.PropertyValue
>> args4(0).Name = "DesignerDialog"
>> args4(0).Value = false
>>
>> dispatcher.executeDispatch(document, ".uno:DesignerDialog", "", 0, args4())
>>
>>
>> end sub
> Sorry I can't help with your macro, but I like your idea.
> An alternative approach I use, is to add my user defined date format to
> my Calc default template.
>
> Dave
>
>
Thank you for responding; I admire your style. I manually changed the
date format of my spreadsheet, saved , then coded it as the default
template. The default template took, but unfortunately, again the
user-defined date format wasn't saved.


Do I understand you can save a user-defined date format in the default
template and it takes? I'm sure a macro would work and I can wade
through the code, but if there's an easier way I'm interested.


--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Pedro Pedro
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

In reply to this post by rhubarbpieguy
rhubarbpieguy wrote
I'd like to create a macro for a user-defined date format (H:MMa/p).  As
examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p.  I can
create the format manually, but I understand the LibreOffice format
can't save user-defined formats.  So my thought is to create a macro
which creates the format each time the spreadsheet is opened.  The
user-defined Format Code is for a saved Style.
Since this is a limitation of the ODF file format and that modifying the default template only applies to your PC (correct me if I'm wrong) wouldn't it make more sense to simply save it as XLS?

I tested with your example and the user-defined time format is saved...

--
Pedro
Dave Barton Dave Barton
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

In reply to this post by rhubarbpieguy
-------- Original Message  --------
From: [hidden email]
To: [hidden email]
Date: Fri, 20 Jul 2012 20:33:27 -0500

> On 07/20/12 02:16, Dave Barton wrote:
>> -------- Original Message  --------
>> From: [hidden email]
>> To: [hidden email]
>> Date: Thu, 19 Jul 2012 16:48:53 -0500
>>
>>> I'd like to create a macro for a user-defined date format (H:MMa/p).  As
>>> examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p.  I can
>>> create the format manually, but I understand the LibreOffice format
>>> can't save user-defined formats.  So my thought is to create a macro
>>> which creates the format each time the spreadsheet is opened.  The
>>> user-defined Format Code is for a saved Style.
>>>
>>> The macro records without incident and the date format is correct.
>>> However, running the saved macro doesn't change the format.  It seems
>>> this should work.  Thoughts?  The recorded macro is as follows:
>>>
8<-- code snip for brevity -->8

>> Sorry I can't help with your macro, but I like your idea.
>> An alternative approach I use, is to add my user defined date format to
>> my Calc default template.
>>
>> Dave
>>
>>
> Thank you for responding; I admire your style. I manually changed the
> date format of my spreadsheet, saved , then coded it as the default
> template. The default template took, but unfortunately, again the
> user-defined date format wasn't saved.
>
>
> Do I understand you can save a user-defined date format in the default
> template and it takes? I'm sure a macro would work and I can wade
> through the code, but if there's an easier way I'm interested.

I am not sure what you mean by "coded it as the default  template".
If you follow this procedure:
http://user.services.openoffice.org/en/forum/viewtopic.php?t=1161
the ".ots" (Calc template) file will include your date format, as would
be the case for any ODF file.
I am sending you (off-list) an example template which has a DD.MM.YYYY
date format, which is not included in standard list of date formats.
Open it and you will find 31.12.1999 at the end of the Format => Date ->
Category format list.

HTH

Dave


--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Andreas Säger Andreas Säger
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

In reply to this post by rhubarbpieguy
rhubarbpieguy wrote
>
Thank you for responding; I admire your style. I manually changed the
date format of my spreadsheet, saved , then coded it as the default
template. The default template took, but unfortunately, again the
user-defined date format wasn't saved.
That would be a severe bug. My default template (including number formats for many purposes) works as it used to work since OOo 2.
rhubarbpieguy rhubarbpieguy
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

In reply to this post by Pedro
On 07/20/12 20:49, Pedro wrote:

> rhubarbpieguy wrote
>> I'd like to create a macro for a user-defined date format (H:MMa/p).  As
>> examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p.  I can
>> create the format manually, but I understand the LibreOffice format
>> can't save user-defined formats.  So my thought is to create a macro
>> which creates the format each time the spreadsheet is opened.  The
>> user-defined Format Code is for a saved Style.
>>
> Since this is a limitation of the ODF file format and that modifying the
> default template only applies to your PC (correct me if I'm wrong) wouldn't
> it make more sense to simply save it as XLS?
>
> I tested with your example and the user-defined time format is saved...
>
> --
> Pedro
>
>
>
> --
> View this message in context: http://nabble.documentfoundation.org/Date-format-macro-tp3996521p3996810.html
> Sent from the Users mailing list archive at Nabble.com.
>
Yes, XLS will save the format, but my macros don't carry over.

--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Dave Barton Dave Barton
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

In reply to this post by Dave Barton
-------- Original Message  --------
From: [hidden email]
To: Dave Barton <[hidden email]>
Date: Sat, 21 Jul 2012 12:59:52 -0500

> On 07/21/12 00:45, Dave Barton wrote:
>> -------- Original Message  --------
>> From: [hidden email]
>> To: [hidden email]
>> Date: Fri, 20 Jul 2012 20:33:27 -0500
>>
>>> On 07/20/12 02:16, Dave Barton wrote:
>>>> -------- Original Message  --------
>>>> From: [hidden email]
>>>> To: [hidden email]
>>>> Date: Thu, 19 Jul 2012 16:48:53 -0500
>>>>
>>>>> I'd like to create a macro for a user-defined date format
>>>>> (H:MMa/p).  As
>>>>> examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p.  I can
>>>>> create the format manually, but I understand the LibreOffice format
>>>>> can't save user-defined formats.  So my thought is to create a macro
>>>>> which creates the format each time the spreadsheet is opened.  The
>>>>> user-defined Format Code is for a saved Style.
>>>>>
>>>>> The macro records without incident and the date format is correct.
>>>>> However, running the saved macro doesn't change the format.  It seems
>>>>> this should work.  Thoughts?  The recorded macro is as follows:
>>>>>
>> 8<-- code snip for brevity -->8
>>>> Sorry I can't help with your macro, but I like your idea.
>>>> An alternative approach I use, is to add my user defined date format to
>>>> my Calc default template.
>>>>
>>>> Dave
>>>>
>>>>
>>> Thank you for responding; I admire your style. I manually changed the
>>> date format of my spreadsheet, saved , then coded it as the default
>>> template. The default template took, but unfortunately, again the
>>> user-defined date format wasn't saved.
>>>
>>>
>>> Do I understand you can save a user-defined date format in the default
>>> template and it takes? I'm sure a macro would work and I can wade
>>> through the code, but if there's an easier way I'm interested.
>> I am not sure what you mean by "coded it as the default  template".
>> If you follow this procedure:
>> http://user.services.openoffice.org/en/forum/viewtopic.php?t=1161
>> the ".ots" (Calc template) file will include your date format, as would
>> be the case for any ODF file.
>> I am sending you (off-list) an example template which has a DD.MM.YYYY
>> date format, which is not included in standard list of date formats.
>> Open it and you will find 31.12.1999 at the end of the Format => Date ->
>> Category format list.
>>
>> HTH
>>
>> Dave
>>
>> .
>>
> Thank you again for responding.  However, I think we're talking apples
> and oranges.  I opened your template and the DD.MM.YYYY user-defined
> format works.  My problem is I can't get the H:MMa/p user-defined Format
> Code to take.  While the document is opened I can change 1:11PM to 1:11p
> for instance.  However, after saving, closing, and reopening the
> document the time appears as 1:11PM, not 1:11p, which is the format code
> I wanted saved.  I've always been able to save the user-defined code, I
> just can't get the lower-case a/p to take.  It does work with other file
> formats.
>
> That happens regardless of whether I save as an .ods or .ots file. I do
> see the user-defined Format Code, but it always comes up as H:MMAM/PM
> even though I save it as H:MMa/p.  I believe I originally created a
> default template correctly, but just redid the process with your
> instructions.  The same thing happens if I save the format in your
> attached template.
>
> So, can you successfully save the H:MMa/p format code?  That would
> address the apples/oranges question.  I'd appreciate your testing that
> if possible.  If it works for you I'm doing something wrong. It's not a
> huge deal to manually change AM/PM to a/p each time I open the
> spreadsheet, but not having to do so would be better.

Your "apples & oranges" analogy is correct. I was misled by your
original reference to "Date" format and although you spelled it out
quite clearly I overlooked the fact that your issue was with "Time" format.

I have now done some testing on this issue, with the following results:
* Saving from LO in ODF (".ods" or ".ots") format does not preserve the
user defined time format you want. (As you have already established.)
* Saving from LO in Excel (".xls") format and reopening it LO does
preserve the format. (As suggested by Pedro in another post to this thread.)

It may or may not be of importance to you, but opening the files saved
from LO and opening them in Excel 2010 I found:
* XLS File: Partially preserves the time format (ie. H:MM), but the
lower case p/m is becomes upper case P/M. The user defined cells are
"locked" (MS terminology) and "unlocking" them the format changes to
whatever MS deems to be appropriate.
* ODF File: Generates an error, which Excel generously offers to fix,
with the same result as for unlocking the cells in the XLS file.

Unless someone with a better knowledge of Star Basic than myself can
offer a solution to your macro problem, I suggest you file a bug/RFE
issue. https://www.libreoffice.org/get-help/bug/

Dave

--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

rhubarbpieguy rhubarbpieguy
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

On 07/21/12 18:46, Dave Barton wrote:

> -------- Original Message  --------
> From: [hidden email]
> To: Dave Barton <[hidden email]>
> Date: Sat, 21 Jul 2012 12:59:52 -0500
>
>> On 07/21/12 00:45, Dave Barton wrote:
>>> -------- Original Message  --------
>>> From: [hidden email]
>>> To: [hidden email]
>>> Date: Fri, 20 Jul 2012 20:33:27 -0500
>>>
>>>> On 07/20/12 02:16, Dave Barton wrote:
>>>>> -------- Original Message  --------
>>>>> From: [hidden email]
>>>>> To: [hidden email]
>>>>> Date: Thu, 19 Jul 2012 16:48:53 -0500
>>>>>
>>>>>> I'd like to create a macro for a user-defined date format
>>>>>> (H:MMa/p).  As
>>>>>> examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p.  I can
>>>>>> create the format manually, but I understand the LibreOffice format
>>>>>> can't save user-defined formats.  So my thought is to create a macro
>>>>>> which creates the format each time the spreadsheet is opened.  The
>>>>>> user-defined Format Code is for a saved Style.
>>>>>>
>>>>>> The macro records without incident and the date format is correct.
>>>>>> However, running the saved macro doesn't change the format.  It seems
>>>>>> this should work.  Thoughts?  The recorded macro is as follows:
>>>>>>
>>> 8<-- code snip for brevity -->8
>>>>> Sorry I can't help with your macro, but I like your idea.
>>>>> An alternative approach I use, is to add my user defined date format to
>>>>> my Calc default template.
>>>>>
>>>>> Dave
>>>>>
>>>>>
>>>> Thank you for responding; I admire your style. I manually changed the
>>>> date format of my spreadsheet, saved , then coded it as the default
>>>> template. The default template took, but unfortunately, again the
>>>> user-defined date format wasn't saved.
>>>>
>>>>
>>>> Do I understand you can save a user-defined date format in the default
>>>> template and it takes? I'm sure a macro would work and I can wade
>>>> through the code, but if there's an easier way I'm interested.
>>> I am not sure what you mean by "coded it as the default  template".
>>> If you follow this procedure:
>>> http://user.services.openoffice.org/en/forum/viewtopic.php?t=1161
>>> the ".ots" (Calc template) file will include your date format, as would
>>> be the case for any ODF file.
>>> I am sending you (off-list) an example template which has a DD.MM.YYYY
>>> date format, which is not included in standard list of date formats.
>>> Open it and you will find 31.12.1999 at the end of the Format => Date ->
>>> Category format list.
>>>
>>> HTH
>>>
>>> Dave
>>>
>>> .
>>>
>> Thank you again for responding.  However, I think we're talking apples
>> and oranges.  I opened your template and the DD.MM.YYYY user-defined
>> format works.  My problem is I can't get the H:MMa/p user-defined Format
>> Code to take.  While the document is opened I can change 1:11PM to 1:11p
>> for instance.  However, after saving, closing, and reopening the
>> document the time appears as 1:11PM, not 1:11p, which is the format code
>> I wanted saved.  I've always been able to save the user-defined code, I
>> just can't get the lower-case a/p to take.  It does work with other file
>> formats.
>>
>> That happens regardless of whether I save as an .ods or .ots file. I do
>> see the user-defined Format Code, but it always comes up as H:MMAM/PM
>> even though I save it as H:MMa/p.  I believe I originally created a
>> default template correctly, but just redid the process with your
>> instructions.  The same thing happens if I save the format in your
>> attached template.
>>
>> So, can you successfully save the H:MMa/p format code?  That would
>> address the apples/oranges question.  I'd appreciate your testing that
>> if possible.  If it works for you I'm doing something wrong. It's not a
>> huge deal to manually change AM/PM to a/p each time I open the
>> spreadsheet, but not having to do so would be better.
> Your "apples & oranges" analogy is correct. I was misled by your
> original reference to "Date" format and although you spelled it out
> quite clearly I overlooked the fact that your issue was with "Time" format.
>
> I have now done some testing on this issue, with the following results:
> * Saving from LO in ODF (".ods" or ".ots") format does not preserve the
> user defined time format you want. (As you have already established.)
> * Saving from LO in Excel (".xls") format and reopening it LO does
> preserve the format. (As suggested by Pedro in another post to this thread.)
>
> It may or may not be of importance to you, but opening the files saved
> from LO and opening them in Excel 2010 I found:
> * XLS File: Partially preserves the time format (ie. H:MM), but the
> lower case p/m is becomes upper case P/M. The user defined cells are
> "locked" (MS terminology) and "unlocking" them the format changes to
> whatever MS deems to be appropriate.
> * ODF File: Generates an error, which Excel generously offers to fix,
> with the same result as for unlocking the cells in the XLS file.
>
> Unless someone with a better knowledge of Star Basic than myself can
> offer a solution to your macro problem, I suggest you file a bug/RFE
> issue. https://www.libreoffice.org/get-help/bug/
>
> Dave
>

I understand your confusion as I should have titled the post "Time
format macro."  Sloppy labeling on my part.

I have reported this as Bug 50923.  That's why I believed it was/is an
.ods limitation and thought of the macro solution.  Your suggestion of a
template piqued my interested as I thought (possibly) a .odt file might
be different.  I'd always assumed the file format identical except a
.odt extension saved the file to the template directory, but it was
worth a try.

I still think the macro solution is the best.  I'll bite the bullet and
do some research as the macro recorder doesn't work.  I do again thank
you for your interest and help.


--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

Johnny Rosenberg Johnny Rosenberg
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

2012/7/22  <[hidden email]>:

> On 07/21/12 18:46, Dave Barton wrote:
>>
>> -------- Original Message  --------
>> From: [hidden email]
>> To: Dave Barton <[hidden email]>
>> Date: Sat, 21 Jul 2012 12:59:52 -0500
>>
>>> On 07/21/12 00:45, Dave Barton wrote:
>>>>
>>>> -------- Original Message  --------
>>>> From: [hidden email]
>>>> To: [hidden email]
>>>> Date: Fri, 20 Jul 2012 20:33:27 -0500
>>>>
>>>>> On 07/20/12 02:16, Dave Barton wrote:
>>>>>>
>>>>>> -------- Original Message  --------
>>>>>> From: [hidden email]
>>>>>> To: [hidden email]
>>>>>> Date: Thu, 19 Jul 2012 16:48:53 -0500
>>>>>>
>>>>>>> I'd like to create a macro for a user-defined date format
>>>>>>> (H:MMa/p).  As
>>>>>>> examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p.  I can
>>>>>>> create the format manually, but I understand the LibreOffice format
>>>>>>> can't save user-defined formats.  So my thought is to create a macro
>>>>>>> which creates the format each time the spreadsheet is opened.  The
>>>>>>> user-defined Format Code is for a saved Style.
>>>>>>>
>>>>>>> The macro records without incident and the date format is correct.
>>>>>>> However, running the saved macro doesn't change the format.  It seems
>>>>>>> this should work.  Thoughts?  The recorded macro is as follows:
>>>>>>>
>>>> 8<-- code snip for brevity -->8
>>>>>>
>>>>>> Sorry I can't help with your macro, but I like your idea.
>>>>>> An alternative approach I use, is to add my user defined date format
>>>>>> to
>>>>>> my Calc default template.
>>>>>>
>>>>>> Dave
>>>>>>
>>>>>>
>>>>> Thank you for responding; I admire your style. I manually changed the
>>>>> date format of my spreadsheet, saved , then coded it as the default
>>>>> template. The default template took, but unfortunately, again the
>>>>> user-defined date format wasn't saved.
>>>>>
>>>>>
>>>>> Do I understand you can save a user-defined date format in the default
>>>>> template and it takes? I'm sure a macro would work and I can wade
>>>>> through the code, but if there's an easier way I'm interested.
>>>>
>>>> I am not sure what you mean by "coded it as the default  template".
>>>> If you follow this procedure:
>>>> http://user.services.openoffice.org/en/forum/viewtopic.php?t=1161
>>>> the ".ots" (Calc template) file will include your date format, as would
>>>> be the case for any ODF file.
>>>> I am sending you (off-list) an example template which has a DD.MM.YYYY
>>>> date format, which is not included in standard list of date formats.
>>>> Open it and you will find 31.12.1999 at the end of the Format => Date ->
>>>> Category format list.
>>>>
>>>> HTH
>>>>
>>>> Dave
>>>>
>>>> .
>>>>
>>> Thank you again for responding.  However, I think we're talking apples
>>> and oranges.  I opened your template and the DD.MM.YYYY user-defined
>>> format works.  My problem is I can't get the H:MMa/p user-defined Format
>>> Code to take.  While the document is opened I can change 1:11PM to 1:11p
>>> for instance.  However, after saving, closing, and reopening the
>>> document the time appears as 1:11PM, not 1:11p, which is the format code
>>> I wanted saved.  I've always been able to save the user-defined code, I
>>> just can't get the lower-case a/p to take.  It does work with other file
>>> formats.
>>>
>>> That happens regardless of whether I save as an .ods or .ots file. I do
>>> see the user-defined Format Code, but it always comes up as H:MMAM/PM
>>> even though I save it as H:MMa/p.  I believe I originally created a
>>> default template correctly, but just redid the process with your
>>> instructions.  The same thing happens if I save the format in your
>>> attached template.
>>>
>>> So, can you successfully save the H:MMa/p format code?  That would
>>> address the apples/oranges question.  I'd appreciate your testing that
>>> if possible.  If it works for you I'm doing something wrong. It's not a
>>> huge deal to manually change AM/PM to a/p each time I open the
>>> spreadsheet, but not having to do so would be better.
>>
>> Your "apples & oranges" analogy is correct. I was misled by your
>> original reference to "Date" format and although you spelled it out
>> quite clearly I overlooked the fact that your issue was with "Time"
>> format.
>>
>> I have now done some testing on this issue, with the following results:
>> * Saving from LO in ODF (".ods" or ".ots") format does not preserve the
>> user defined time format you want. (As you have already established.)
>> * Saving from LO in Excel (".xls") format and reopening it LO does
>> preserve the format. (As suggested by Pedro in another post to this
>> thread.)
>>
>> It may or may not be of importance to you, but opening the files saved
>> from LO and opening them in Excel 2010 I found:
>> * XLS File: Partially preserves the time format (ie. H:MM), but the
>> lower case p/m is becomes upper case P/M. The user defined cells are
>> "locked" (MS terminology) and "unlocking" them the format changes to
>> whatever MS deems to be appropriate.
>> * ODF File: Generates an error, which Excel generously offers to fix,
>> with the same result as for unlocking the cells in the XLS file.
>>
>> Unless someone with a better knowledge of Star Basic than myself can
>> offer a solution to your macro problem, I suggest you file a bug/RFE
>> issue. https://www.libreoffice.org/get-help/bug/
>>
>> Dave
>>
>
> I understand your confusion as I should have titled the post "Time format
> macro."  Sloppy labeling on my part.
>
> I have reported this as Bug 50923.  That's why I believed it was/is an .ods
> limitation and thought of the macro solution.  Your suggestion of a template
> piqued my interested as I thought (possibly) a .odt file might be different.
> I'd always assumed the file format identical except a .odt extension saved
> the file to the template directory, but it was worth a try.
>
> I still think the macro solution is the best.  I'll bite the bullet and do
> some research as the macro recorder doesn't work.  I do again thank you for
> your interest and help.

There is a document called AndrewMacro.pdf (and there is an ODF
version too, called AndrewMacro.odt) somewhere. There are a lot of
explaining and a lot of examples, and I think date format examples are
included as well. However, I couldn't find it for download. I found
this page (http://www.pitonyak.org/oo.php/), but clicking on the links
only took me back to the page, and forcing download only downloaded an
18.3 kB document in HTML format…

Maybe someone else have a better link.


Here's the date format paragraph anyway (I removed a comment
containing the authors email address, just in case), might be of some
kind of help:
 7.7.  Fields
 7.7.1.  Insert a formatted date field into a Write document
This will insert the text “Today is <date> ” where the date is
formatted as “DD. MMM YYYY”. This will create the date format if it
does not exist. For more information on valid formats, see the help
contents on topic “number formats; formats”.
Listing 7.31: Insert a formatted date field into a Write document.
'Author: Andrew Pitonyak
'uses:  FindCreateNumberFormatStyle
Sub InsertDateField
  Dim oDoc As Object
  Dim oText As Object
  Dim oVCurs As Object
  Dim oTCurs As Object
  Dim oDateTime As Object

  oDoc = ThisComponent
  If oDoc.SupportsService("com.sun.star.text.TextDocument") Then
    oText = oDoc.Text
    oVCurs = oDoc.CurrentController.getViewCursor()
    oTCurs = oText.createTextCursorByRange(oVCurs.getStart())
    oText.insertString(oTCurs, "Today is ", FALSE)
    ' Create the DateTime type.
    ODateTime = oDoc.createInstance("com.sun.star.text.TextField.DateTime")
    oDateTime.IsFixed = TRUE
    oDateTime.NumberFormat = FindCreateNumberFormatStyle(_
      "DD. MMMM YYYY", oDoc)

    oText.insertTextContent(oTCurs,oDateTime,FALSE)
    oText.insertString(oTCurs," ",FALSE)  Else
    MsgBox "Sorry, this macro requires a TextDocument"
  End If
End Sub



Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
Andreas Säger Andreas Säger
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

In reply to this post by rhubarbpieguy
Am 19.07.2012 23:48, [hidden email] wrote:

>
> I'd like to create a macro for a user-defined date format (H:MMa/p).  As
> examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p.  I can
> create the format manually, but I understand the LibreOffice format
> can't save user-defined formats.  So my thought is to create a macro
> which creates the format each time the spreadsheet is opened.  The
> user-defined Format Code is for a saved Style.
>
> The macro records without incident and the date format is correct.
> However, running the saved macro doesn't change the format.  It seems
> this should work.  Thoughts?  The recorded macro is as follows:
>

Hello,

The issue is a known one (AOO bug #66842). The office seems to support
some format codes that have no equivalent expression in the ODF standard.
It has been discussed in a productive manner here:
http://user.services.openoffice.org/en/forum/viewtopic.php?f=9&t=53724
http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=55344

I attached simple Basic macro to a demo document:
http://user.services.openoffice.org/en/forum/download/file.php?id=14598

It links number formats to cell styles so the newly generated number
formats applies to all the cells where the style is in use.

Hope this helps,
A.S.


--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted

rhubarbpieguy rhubarbpieguy
Reply | Threaded
Open this post in threaded view
|

Re: Date format macro.

On 07/27/12 05:14, Andreas Säger wrote:

> Am 19.07.2012 23:48, [hidden email] wrote:
>>
>> I'd like to create a macro for a user-defined date format (H:MMa/p).  As
>> examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p. I can
>> create the format manually, but I understand the LibreOffice format
>> can't save user-defined formats.  So my thought is to create a macro
>> which creates the format each time the spreadsheet is opened. The
>> user-defined Format Code is for a saved Style.
>>
>> The macro records without incident and the date format is correct.
>> However, running the saved macro doesn't change the format.  It seems
>> this should work.  Thoughts?  The recorded macro is as follows:
>>
>
> Hello,
>
> The issue is a known one (AOO bug #66842). The office seems to support
> some format codes that have no equivalent expression in the ODF standard.
> It has been discussed in a productive manner here:
> http://user.services.openoffice.org/en/forum/viewtopic.php?f=9&t=53724
> http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=55344
>
> I attached simple Basic macro to a demo document:
> http://user.services.openoffice.org/en/forum/download/file.php?id=14598
>
> It links number formats to cell styles so the newly generated number
> formats applies to all the cells where the style is in use.
>
> Hope this helps,
> A.S.
>
>
Thank you!  That's a very good solution which I'll use - problem
solved.  I also thank Johnny Rosenberg for his suggestion.


--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
rhubarbpieguy rhubarbpieguy
Reply | Threaded
Open this post in threaded view
|

[Solved] Re: [libreoffice-users] Re: Date format macro.

In reply to this post by Andreas Säger
On 07/27/12 05:14, Andreas Säger wrote:

> Am 19.07.2012 23:48, [hidden email] wrote:
>>
>> I'd like to create a macro for a user-defined date format (H:MMa/p).  As
>> examples, 7:00 AM would display as 7:00a and 3:33 PM as 3:33p. I can
>> create the format manually, but I understand the LibreOffice format
>> can't save user-defined formats.  So my thought is to create a macro
>> which creates the format each time the spreadsheet is opened. The
>> user-defined Format Code is for a saved Style.
>>
>> The macro records without incident and the date format is correct.
>> However, running the saved macro doesn't change the format.  It seems
>> this should work.  Thoughts?  The recorded macro is as follows:
>>
>
> Hello,
>
> The issue is a known one (AOO bug #66842). The office seems to support
> some format codes that have no equivalent expression in the ODF standard.
> It has been discussed in a productive manner here:
> http://user.services.openoffice.org/en/forum/viewtopic.php?f=9&t=53724
> http://user.services.openoffice.org/en/forum/viewtopic.php?f=20&t=55344
>
> I attached simple Basic macro to a demo document:
> http://user.services.openoffice.org/en/forum/download/file.php?id=14598
>
> It links number formats to cell styles so the newly generated number
> formats applies to all the cells where the style is in use.
>
> Hope this helps,
> A.S.
>
> I'm uncertain of the proper method of labeling this as solved. But,
> for my purposes it is and as I began the thread, perhaps [Solved] is
> appropriate.



--
For unsubscribe instructions e-mail to: [hidden email]
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted