Page 1 of 1

[Solved] Sheets - getByReference

Posted: Fri Jun 14, 2019 9:13 am
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

Re: Sheets - getByReference

Posted: Fri Jun 14, 2019 9:46 am
by JeJe
Works for me.

Re: Sheets - getByReference

Posted: Fri Jun 14, 2019 9:47 am
by RoryOF
File format used?

Re: Sheets - getByReference

Posted: Fri Jun 14, 2019 9:48 am
by gurkand
RoryOF wrote:File format used?
.ods

Re: Sheets - getByReference

Posted: Fri Jun 14, 2019 9:56 am
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

Re: Sheets - getByReference

Posted: Fri Jun 14, 2019 9:59 am
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.

Re: Sheets - getByReference

Posted: Fri Jun 14, 2019 5:30 pm
by gurkand
Switched to LibreOffice 6.2.

It works perfectly fine now.

Thanks