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]

Reply via email to