Object Variable not set

Creating a macro - Writing a Script - Using the API

Object Variable not set

Postby iFunction » Thu Jul 07, 2016 3:44 pm

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   Expand viewCollapse view
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: https://forum.openoffice.org/en/forum/v ... 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   Expand viewCollapse view
CellRange = Sheet.getCellRangeByPosition

Which should actually read:
Code: Select all   Expand viewCollapse view
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.

LibreOffice on Raspberry Pi
Posts: 48
Joined: Tue May 24, 2016 3:37 pm

Re: Object Variable not set

Postby ThierryT » Thu Jul 07, 2016 4:08 pm

Read this link about the difference between the two methods : https://www.openoffice.org/api/docs/com ... Range.html
LibreOffice x 64 and AOO 4.1.3 Windows x64
Posts: 11
Joined: Fri May 13, 2016 8:52 pm

Re: Object Variable not set

Postby UnklDonald418 » Thu Jul 07, 2016 5:06 pm

There is a discussion about your error message at

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.8 & LibreOffice - Windows 10 Professional
Posts: 1412
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 10 guests