[Solved] Assigning NULL to an Object [Calc] Use NOTHING
Posted: Wed Feb 22, 2017 6:53 pm
I apparently have a fundamental misunderstanding about my failure to be able to assign the NULL value to an Object. In the following code, the spreadsheet mSS and the sheet mSheet are assigned a SS object and a sheet object, as expected. But my code is not allowed to assign NULL to mSheet in the last line of code. Instead, I get the error message "Object variable not set." I thought NULL was a special value that could be assigned to something, but the error message seems to be saying that NULL is an object variable that has not been set. ???
I need to pass mSheet to another function (in a more complicated situation than shown here). Sometimes there is an actual sheet but at other times there is no sheet, and I need to pass a Null value to indicate this. After the SS is closed, mSheet still refers to the original object, as one would expect, since mSS.close(True) does not "know" what use was being made of its sheets.
What's a workable way to do this? As I said, I seem to have a basic misunderstanding about this. Thanks for your help.
I need to pass mSheet to another function (in a more complicated situation than shown here). Sometimes there is an actual sheet but at other times there is no sheet, and I need to pass a Null value to indicate this. After the SS is closed, mSheet still refers to the original object, as one would expect, since mSS.close(True) does not "know" what use was being made of its sheets.
What's a workable way to do this? As I said, I seem to have a basic misunderstanding about this. Thanks for your help.
Code: Select all
Sub NullTest
Dim mSS as Object
Dim mSheet as Object
mSS = StarDesktop.LoadComponentFromUrl( "private:factory/scalc", "_blank", 0, Array())
mSheet = mSS.Sheets(0)
mSS.close(True)
mSheet = Null ' fails: Object variable not set
End Sub