I think the Xray is a 3rd-party Editor. Not be given by the OOo. I can not visit most of the websites with my company network , and will try to find it out when i back home . Keep in touch if anyone find it first :-)
-----Original Message----- From: Clifton Liles [mailto:[email protected]] Sent: Monday, June 01, 2009 5:00 AM To: [email protected] Subject: Re: [users] How to get current cell in Basic Macro Johnny Rosenberg wrote: > 2009/5/22 陈浩(Chen Hao) <[email protected]>: > >> When I use the MS-Excel , I offen use "Ctrl+;" to insert the current >> date to a cell or after some strings in a cell. >> But i find OOo-Calc did not supply this function or I haven't found it. >> >> So i want to write a Macro to do this , but there are two problems , >> and i think maybe someone could give me a hand. >> >> 1. how to get the current selected cell with basic ? So that i could >> modify it . >> 2. how to change the path that saving the user-defined macros? I >> offen forgot to backup those things in C-disk when i reinstall my >> Windows OS >_< >> >> Thanks very much! >> >> Chen Hao >> Dalian , China >> > > Here's a macro I fou(nd in a forum somewhere: > > 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 "You can't do that here" > EndIf > End Sub > > So obviously the currently selected cell is > ThisComponent.getCurrentController().getSelection() > > To get the current stuff from it there are things liks getValue() and > getString(). > To change the value, you can use, for example, setValue(47.3) and > setString("Hello World") respectively. > > I think there are also a getFormula() and setFormula() available, but > I am not sure. Use Xray to find out what methods are available for a > specific object. It's the most helpful tool I used so far with > OpenOffice.org BASIC. I think it is installed by default these days, > if not you can find it somewhere, use google… > > Well, I guess you got it by now. > > Johnny Rosenberg > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] For > additional commands, e-mail: [email protected] > > > Hi Johnny I've looked in the help files and I can't find anything on Xray. If it comes with the openoffice install , where is it? If not, I'll find it, but if it is part of the install I would like to use that. Sounds very interesting. Also I have modified the script above to change the format to DATE. So just for your information: ------------------------------------------ REM ***** BASIC ***** ' This macro will get the current date and insert the value in ' the cell and then format the cell to display in date format. ' ' Original code from: OOUsers email from Johnny Rosenberg. [email protected] ' Format code from: "Useful Macro Information for OpenOffice.org" By Andrew Pitonyak ' Clifton R. Liles "Software to the Stars" [email protected] Sub InsertDate Dim oCell As Object Dim oFormats 'Available formats oCell=ThisComponent.getCurrentController().getSelection() If oCell.SupportsService("com.sun.star.sheet.SheetCell") Then ' Selection is a single cell oCell.Value=(DateValue(Now())) ' oCell.Value= Now() Rem Set the date number format to the default date format ' also DATETIME & TIME oFormats = ThisComponent.NumberFormats Dim aLocale As New com.sun.star.lang.Locale oCell.NumberFormat = oFormats.getStandardFormat(_ com.sun.star.util.NumberFormat.DATE, aLocale) Else MsgBox "You can't do that here" EndIf End Sub ------------------------------------------------- I have left a few hints on how to set the time and datetime. Cliff -- mailto: [email protected] Clifton R. Liles "Software to the Stars" [email protected] Pearland, TX 77581 [email protected] [email protected] - Speaking for myself! Standard disclaimer applies. - This address may *not* be used for unsolicited mailings. Failure is not an option. It comes bundled with your Microsoft products. --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] --------------------------------------------------------------------------------------------------- Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s) is intended only for the use of the intended recipient and may be confidential and/or privileged of Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying is strictly prohibited, and may be unlawful.If you have received this communication in error,please immediately notify the sender by return e-mail, and delete the original message and all copies from your system. Thank you. ---------------------------------------------------------------------------------------------------
