Object Variable not set

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
iFunction
Posts: 48
Joined: Tue May 24, 2016 3:37 pm

Object Variable not set

Post 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
LibreOffice on Raspberry Pi
ThierryT
Posts: 11
Joined: Fri May 13, 2016 8:52 pm

Re: Object Variable not set

Post by ThierryT »

Read this link about the difference between the two methods : https://www.openoffice.org/api/docs/com ... Range.html
LibreOffice 5.3.2.1 x 64 and AOO 4.1.3 Windows x64
UnklDonald418
Volunteer
Posts: 1566
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Object Variable not set

Post 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.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Post Reply