Got it. You give a large help, thx! 

-----Original Message-----
From: Johnny Rosenberg [mailto:[email protected]] 
Sent: Friday, May 29, 2009 2:26 AM
To: [email protected]
Subject: Re: [users] How to get current cell in Basic Macro

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]

---------------------------------------------------------------------------------------------------
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. 
---------------------------------------------------------------------------------------------------

Reply via email to