Page 1 of 1

Object Variable not set

Posted: Thu Jul 07, 2016 3:44 pm
by iFunction
Please could someone explain to me what this means, it keeps cropping up in my program at the most random times, and I can't find any information about the actual principles of the error.

I need to understand this, it is the most common error that I get when trying to write macro's in Open Office? The latest one is from a bit of code I found on here funnily enough to loop through a range of Cells, unfortunately I can't get it going so can't learn anything from it. If someone could explain what the error means that would really help.

Code: Select all

Dim Doc, Sheet, Descript, Cell, CellRange as object
Dim i as integer
Doc = ThisComponent
Sheet = Doc.Sheets(0)
For i = 2 to 6
CellRange = Sheet.getCellRangeByPosition(2,i,4,i)
Descript = CellRange.createSearchDescriptor()
Descript.SearchString = "54321"
Descript.SearchWords = True 'If true, the search will match only complete words
Cell = CellRange.findFirst(Descript)
If Not IsNull(Cell) then
Print "Row = " + (Cell.CellAddress.Row + 1)
End if
next i
I got this from here: viewtopic.php?f=25&t=16132
and judging by the thank yous it must have worked at some point but as the thread was 2009 I can only assume that the syntax has now changed as noted in the line:

Code: Select all

CellRange = Sheet.getCellRangeByPosition
Which should actually read:

Code: Select all

CellRange = Sheet.getCellByPosition
Is there a list of these kind of errors so you can learn to understand what they mean, as they are somewhat cryptic unless you are an accomplished programmer.

Regards
ifunct

Re: Object Variable not set

Posted: Thu Jul 07, 2016 4:08 pm
by ThierryT
Read this link about the difference between the two methods : https://www.openoffice.org/api/docs/com ... Range.html

Re: Object Variable not set

Posted: Thu Jul 07, 2016 5:06 pm
by UnklDonald418
There is a discussion about your error message at
viewtopic.php?f=39&t=23732

by the way the original code you posted works for me.