[Solved] Assigning an Object variable

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
alanbeban
Posts: 4
Joined: Sun Oct 22, 2017 2:57 am

[Solved] Assigning an Object variable

Post 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?
Last edited by Hagar Delest on Fri Nov 24, 2017 9:38 am, edited 2 times in total.
Reason: tagged solved
Open Office macOS Sierra 10.12.6
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Assigning an Object variable

Post 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.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
alanbeban
Posts: 4
Joined: Sun Oct 22, 2017 2:57 am

Re: Assigning an Object variable

Post 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.
Open Office macOS Sierra 10.12.6
Post Reply