On 10/27/2012 03:22 PM, Johnny Rosenberg wrote:
2012/10/27 . <Look@ebookring.net>:
On 10/27/2012 01:29 PM, . wrote:
On 10/27/2012 01:06 PM, Tom Davies wrote:
Hi :)
Can you copy&paste the macro's code into a reply as text? If we could see the code then some
people here might be able to spot the error.
Good luck and regards from
Tom :)
Here's the code-
REM ***** BASIC *****
Sub Main
End Sub
sub Insert_Line_and_Date
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(1) as new com.sun.star.beans.PropertyValue
args1(0).Name = "GraphicName"
args1(0).Value = ""
args1(1).Name = "IsSimpleLine"
args1(1).Value = true
dispatcher.executeDispatch(document, ".uno:InsertGraphicRuler", "", 0,
args1())
rem ----------------------------------------------------------------------
dim args2(5) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Type"
args2(0).Value = 0
args2(1).Name = "SubType"
args2(1).Value = 0
args2(2).Name = "Name"
args2(2).Value = ""
args2(3).Name = "Content"
args2(3).Value = "0"
args2(4).Name = "Format"
args2(4).Value = 5122
args2(5).Name = "Separator"
args2(5).Value = " "
dispatcher.executeDispatch(document, ".uno:InsertField", "", 0, args2())
rem ----------------------------------------------------------------------
dim args3(0) as new com.sun.star.beans.PropertyValue
args3(0).Name = "Text"
args3(0).Value = ", "
dispatcher.executeDispatch(document, ".uno:InsertText", "", 0, args3())
rem ----------------------------------------------------------------------
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "Template"
args4(0).Value = "Heading 1"
args4(1).Name = "Family"
args4(1).Value = 2
dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args4())
end sub
________________________________
From: . <Look@eBookRing.net>
To: users@global.libreoffice.org
Sent: Saturday, 27 October 2012, 17:59
Subject: [libreoffice-users] Date changes to a 5 digit number
I made a macro that inserts the date (fixed) as (for example) "July 30,
2012,"
However, after running the macro a fews time the date then appears as
some 5 digit number.
How do I fix this date problem?
--
www.eBookRing.net
The designer and maker of the original eBookRing
The perfect stand for eReaders, iPads, iPhones, tablet computers and other electronic devices.
Patent Pending
--
For unsubscribe instructions e-mail to: users+help@global.libreoffice.org
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
--
www.eBookRing.net
The designer and maker of the original eBookRing
The perfect stand for eReaders, iPads, iPhones, tablet computers and other electronic devices.
Patent Pending
Looks like you actually used that crappy macro recorder…
Maybe this macro could give you a hint or two, I paste it from the
AndrewMacro.pdf document:
'******************************************************************
'Author: Andrew Pitonyak
'uses: FindCreateNumberFormatStyle
Sub InsertDateIntoCell
Dim oSelection 'The currently selected cell
Dim oFormats
'Available formats
REM Verify that this is a Calc document
If ThisComponent.SupportsService("com.sun.star.sheet.SpreadsheetDocument")
Then
oSelection = ThisComponent.CurrentSelection
Rem Set the time, date, or date and time
'oSelection.setValue(DateValue(Now()))
'Set only the date
'oSelection.setValue(TimeValue(Now()))
'Set only the time
oSelection.setValue(Now())
'Set the date and time
Rem I could use FunctionAccess to set the date and/or time.
'Dim oFunction
'Use FunctionAccess service to call the Now function
'oFunction = CreateUnoService("com.sun.star.sheet.FunctionAccess")
'oFunction.NullDate = ThisComponent.NullDate
'oSelection.setValue(oFunction.callFunction("NOW", Array()))
Rem Set the date number format to default
oFormats = ThisComponent.NumberFormats
Dim aLocale As New com.sun.star.lang.Locale
oSelection.NumberFormat = oFormats.getStandardFormat(_
com.sun.star.util.NumberFormat.DATETIME, aLocale)
Rem Set the format to something completely different
'oSelection.NumberFormat = FindCreateNumberFormatStyle(_
' "YYYYMMDD.hhmmss", doc)
Else
MsgBox "This macro must be run in a spreadsheet document"
End If
End Sub
Function FindCreateNumberFormatStyle (_sFormat As String, Optional
doc, Optional locale)
Dim oDoc As Object
Dim aLocale As New com.sun.star.lang.Locale
Dim oFormats As Object
Dim formatNum As Integer
oDoc = IIf(IsMissing(doc), ThisComponent, doc)
oFormats = oDoc.getNumberFormats()
'If you choose to query on types, you need to use the type
'com.sun.star.util.NumberFormat.DATE
'I could set the locale from values stored at
'http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt
'http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
'I use a NULL locale and let it use what ever it likes.
'First, see if the number format exists
If ( Not IsMissing(locale)) Then
aLocale = locale
End If
formatNum = oFormats.queryKey (sFormat, aLocale, TRUE)
MsgBox "Current Format number is" & formatNum
'If the number format does not exist then add it
If (formatNum = -1) Then
formatNum = oFormats.addNew(sFormat, aLocale)
If (formatNum = -1) Then formatNum = 0
MsgBox "new Format number is " & formatNum
End If
FindCreateNumberFormatStyle = formatNum
End Function
I made a very short one that only inserts the date number into a
pre-formatted cell (which on the other hand doesn't solve your
problem, but here it is anyway…):
REM ***** BASIC *****
Option Explicit
Sub InsertDate
Dim oCell As Object
oCell=ThisComponent.getCurrentController().getSelection()
If oCell.SupportsService("com.sun.star.sheet.SheetCell") Then '
Selection is a single cell
oCell.setValue(Now())
Else
MsgBox "Please do that elsewhere!"
EndIf
End Sub
Sometimes it doesn't have to be more complicated than that…
Sadly, the above code is meaningless to me. I'm not using Calc- the
problem occurs in Writer.
--
www.eBookRing.net
The designer and maker of the original eBookRing
The perfect stand for eReaders, iPads, iPhones, tablet computers and other electronic devices.
Patent Pending
--
For unsubscribe instructions e-mail to: users+help@global.libreoffice.org
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
Context
Re: [libreoffice-users] Date changes to a 5 digit number · Jean-Francois Nifenecker
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.