Page 1 of 1

[Solved] Assigning an Object variable

Posted: Sun Oct 22, 2017 3:06 am
by alanbeban
I am trying to run the following Sub-procedure with the indicated result

Code: Select all

Sub Main
  Dim wb, ws1, cell1 As object

  wb=ThisComponent
  ws1=wb.Sheets.getByIndex(0)
  cell1=ws1.getCellByPosition(2,0)
  
  cell1.SetValue(12)
  msgbox cell1.getValue
  
exit sub
'BASIC runtime error
'Property or method not found: Sheets

What's the problem?

Re: Assigning an Object variable

Posted: Sun Oct 22, 2017 4:38 am
by FJCC
Your code works for me after I changed "exit sub" to "end sub". What steps are you taking to run the code? Where is the macro stored? In my case, I stored the macro within the Calc document.

Re: Assigning an Object variable

Posted: Sun Oct 22, 2017 5:00 am
by alanbeban
I just went back and it runs for me now, too. The exit sub doesn't matter; I had other code following what I posted that had nothing to do with the problem. When I added Option VBASupport 1 at the top of the module (based on some other stuff I had read in this forum), the error message changed to "BASIC error '436' or some such. Now, as I said, it runs error free. Although it's no longer relevant, I have no idea where it's stored--don't even really understand the question. I just opened an Open Office spreadsheet and got to the module through clicking on Tools. Well, live and learn--though I don't know what it is I really learned.

Thanks for responding.