Property or method not found: getCellAddress

I am using the following code to determine a cell address in a Do Loop:
oActiveCell = ThisComponent.getCurrentSelection()
oConv = ThisComponent.createInstance(“com.sun.star.table.CellAddressConversion”)
oConv.Address = oActiveCell.getCellAddress
On the first use the code within the loop it works but on the second use I get the errorr “Property or method not found: getCellAddress”

What do I have to do to make the code work within the loop?

I suggest you to install one of the excellent Object inspection Tools: XrayTool or MRI. Then you will able to examine the existing properties and methods of the programming objects.

Note: a selected single Cell has, but a selected Cell Range has not method getCellAddress. A Cell Range has the method getRangeAddress.

My tip: check if the actual selection is a single Cell or is it a Cell Range.

There is always one active cell in a Calc window. Unfortunately, the API has no direct method to get this cell. The following function returns the active cell for any Calc window, the currently active one by default.

Function getActiveCell(Optional oView)
Dim as1(), lSheet&,lCol&,lRow$, sDum as String,bErr as Boolean
If isMissing(oView) then oView = ThisComponent.getCurrentController()
	as1()  = Split(oView.ViewData, ";")
	lSheet = CLng(as1(1))
	sDum = as1(lSheet +3)
	as1() = Split(sDum, "/")
	on error goto errSlash
		lCol = CLng(as1(0))
		lRow = CLng(as1(1))
	on error goto 0
	getActiveCell = oView.Model.getSheets.getByIndex(lSheet).getcellByPosition(lCol,lRow)
exit Function
errSlash:
	if NOT(bErr) then
		bErr = True
		as1() = Split(sDum, "+")
		resume
	endif
End Function

Thanks to all for your suggestions.
I’d like to repeat my problem. On the first iteration of my do loop, the code I presented works. I am searching for a single cell that contains a particular string. On the second iteration, the next cell that is found with that particular string BUT the code no longer works. The part of the code that does not work is “oConv.Address = oActiveCell.getCellAddress”
The question is why doesn’t it work? Keep in mind there’s no issue with the first iteration. Why does “Property or method not found: getCellAddress” occur after the second iteration but not the first?
That is the question.

As already said: If the object you ask for its CellAddress actually is a single cell, the method will be present and found.
You originally defined your object oActiveCell as the document’s CurrentSelection (at the time the statement was executed). Your code will have changed something since. Otherwise you wouldn’t ask for the CellAddress of the unchanged object a second time, would you?
What was changed we cannot even guess without knowing your code.
It looks a bit as if you copied something from Andrew’s “Useful Macro Information” (Listing 6.12?) .
The service described there is (imo) rarely used and poorly documented. The current SDK API reference doesn’t mention it.

The CurrentSelection mostly isn’t a single cell, but a SheetCellRange or a SheetCellRanges object. A SheetCellRange hasn’t a CellAddress. A SheetCellRanges object also hasn’t a RangeAddress.
Your loop, whatever it does, should be suspected to change the selection to something not being a single cell.
A SpreadsheetDocument, however, always has exactly one cell having or being prepared to get the keyboard focus. That’s the object Villeroy’s function will reurn.

I tested the code by creating an external macro with just the code. That worked; therefore, something was happening before the code. It took more time than I’d like to admit but I could not see what was happening between the first and second iteration. When I finally did see, I saw that the focus was still on a “Paste”, which was a range of cells. I inserted a “GoToCell” to another cell after the “Paste”, and everything worked as expected.

Thanks to all for your comments!