We will be migrating from Ask to Discourse on the first week of August, read the details here

Ask Your Question

How can I select the value of an active cell in calc [closed]

asked 2014-12-13 11:36:27 +0200

jobzombi gravatar image

updated 2020-07-11 23:29:59 +0200

Alex Kemp gravatar image

In VisualB it is ActiveCell.Value, but I cannot seem to find it in LOBasic.

This is my VB script:

command = ActiveCell.Value
If Left(command, 3) = "10." Then
command = "ping " + command
End If
If Left(command, 4) = "ping" Then
vbReturn = Shell(command, vbNormalFocus)
vbReturn = MsgBox("Select Ping Command or IP Address" & vbCrLf & "Then Press: Execute Ping Command", vbOKOnly)
Exit Sub
End If

I'd greatly appreciate any help I can get. I'm assuming the vbReturn and vbOKOnly may also be different.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2016-03-07 02:50:48.775835

1 Answer

Sort by » oldest newest most voted

answered 2014-12-13 18:34:56 +0200

Lupp gravatar image

updated 2014-12-21 12:29:03 +0200

There may be a few words in VB having an exact equivalent in LibO Basic - and even fewer are identical. At least when access to objects (documents and everything inside them) and their properties comes in account, the two follow completely different concepts. The gap might be wider than that between Kisuaheli and Mandarin.

There won't be a predefined object like 'ActiveCell'. The one predefined object variable of that style I know is 'ThisComponent' and its "value" may as well be a Writer document as a Calc document or a document of any class LibreOffice is knowing of. Just 'This'! If 'ThisComponent' actually is a Calc document (and will conatain Calc cells, among them, may be, something like an 'ActiveCell') you will have to test by a method call. 'ThisComponent.supportsService("com.sun.star.sheet.SpreadsheetDocument")' will return TRUE if so and FALSE otherwise. But you won't actually need to do that. If your Sub was called from a Calc document you know in advance.

Any document class should possess a method 'getCurrentSelection()' and, talking of a Calc document it will return an object, let's assign it as value to oSel, which then can answer the question 'oSel.supportsService("com.sun.star.sheet.SheetCell")'. If the answer is TRUE you may use the property value 'oSel.Value' and proceed. You also may prepare an error-handling and try 'oSel.Value' without a preceding test.

If you actually want to program in LibO Basic or to "convert" VB code to it, you should start studying "The Book" and the "Useful Information" by Andrew Pitonyak, both available here in odt and in pdf as well. I only go to Basic if unavoidable. The very few things I know about it I got from the sources mentioned above.


As soon as there is a valid object of the cell class, say oCell [ you may check by:

If oCell.supportsService("com.sun.star.sheet.SheetCell") ], you have access to any of its properties, among them 'Value', 'String' and 'Formula'. There are also the related methods 'getValue()', 'setValue(NewValue)' and the respective ones.

Confer listing 6.6 in A. Pitonyak's "Useful ... Informations", p 139, version 2014-06-14.

edit flag offensive delete link more


I know javascript and python is supported too as macros, what else can be used?

jobzombi gravatar imagejobzombi ( 2014-12-14 04:52:02 +0200 )edit

The support - in principle - for any programming language/system someone wrote an uno-implementation and bridge for is, imo, the reason for accepting some complications coming with the uno concept. The extensive incompatibility with VBA on the othert hand, is due to the uno-concept, too - and to the portability requirements.

However, I am not the one to answer your questions from profound knowledge. Hope someone else will do. You may have a look into http://www.openoffice.org/udk/ .

Lupp gravatar imageLupp ( 2014-12-14 16:03:10 +0200 )edit

I took a look at Pitonyak's macro guide, and while I was able to figure out getting the address of the active cell, I still can't figure out getting the value of the cell and saving it to a variable, so I can then run a command with it.

jobzombi gravatar imagejobzombi ( 2014-12-21 09:01:33 +0200 )edit

Question Tools

1 follower


Asked: 2014-12-13 11:36:27 +0200

Seen: 3,857 times

Last updated: Dec 21 '14