[Solved] Sheets - getByReference

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
gurkand
Posts: 29
Joined: Wed Feb 28, 2018 10:27 am

[Solved] Sheets - getByReference

Post by gurkand »

Hello All,

I am trying to Access Calc Sheets with the following call:

Sheet = Doc.Sheets.getByName("CompanyA")

But, I wan't to Access the sheet with a reference, instead of a hard coded value. Like the following;

Dim CName As String
CName = "CompanyA"
Sheet = Doc.Sheets.getByName(CName)

This does not work. I tried using value(CName) which did not help either. Can I? How?

Nope, I dont want to lock myself to Sheet = Doc.Sheets(n) as it brings complications in the Management of the Doc.

Thanks in advance.

Gürkan
Last edited by RoryOF on Fri Jun 14, 2019 11:07 pm, edited 2 times in total.
Reason: Added green tick [RoryOF, Moderator]
LibreOffice 6.3
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: Sheets - getByReference

Post by JeJe »

Works for me.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Sheets - getByReference

Post by RoryOF »

File format used?
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
gurkand
Posts: 29
Joined: Wed Feb 28, 2018 10:27 am

Re: Sheets - getByReference

Post by gurkand »

RoryOF wrote:File format used?
.ods
LibreOffice 6.3
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: Sheets - getByReference

Post by JeJe »

Pare down to the minimum - Close everything. Open a new doc. Put your code in the main sub with the sheet changed to "Sheet1". What error message do you get if you get one? What do you mean by it doesn't work?

Code: Select all

sub Main
Dim CName As String
CName = "Sheet1"
Sheet = ThisComponent.Sheets.getByName(CName)
end sub
Edit:oops changed Doc to thisComponent
Last edited by JeJe on Fri Jun 14, 2019 9:59 am, edited 1 time in total.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Sheets - getByReference

Post by RoryOF »

If these sheets were originally in .xls format (as the mention of Access might lead us to suspect), then there could be a legacy problem, much as we see in Writer when files have been saved in, or originate in, .doc format.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
gurkand
Posts: 29
Joined: Wed Feb 28, 2018 10:27 am

Re: Sheets - getByReference

Post by gurkand »

Switched to LibreOffice 6.2.

It works perfectly fine now.

Thanks
LibreOffice 6.3
Post Reply