[Solved] Sheets - getByReference

Keyboard macros or custom scripts

[Solved] Sheets - getByReference

Postby gurkand » Fri Jun 14, 2019 9:13 am

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.2
gurkand
 
Posts: 18
Joined: Wed Feb 28, 2018 10:27 am

Re: Sheets - getByReference

Postby JeJe » Fri Jun 14, 2019 9:46 am

Works for me.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 523
Joined: Wed Mar 09, 2016 2:40 pm

Re: Sheets - getByReference

Postby RoryOF » Fri Jun 14, 2019 9:47 am

File format used?
Apache OpenOffice 4.1.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29103
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Sheets - getByReference

Postby gurkand » Fri Jun 14, 2019 9:48 am

RoryOF wrote:File format used?


.ods
LibreOffice 6.2
gurkand
 
Posts: 18
Joined: Wed Feb 28, 2018 10:27 am

Re: Sheets - getByReference

Postby JeJe » Fri Jun 14, 2019 9:56 am

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   Expand viewCollapse view
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.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 523
Joined: Wed Mar 09, 2016 2:40 pm

Re: Sheets - getByReference

Postby RoryOF » Fri Jun 14, 2019 9:59 am

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.6 on Xubuntu 18.04.2 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 29103
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Sheets - getByReference

Postby gurkand » Fri Jun 14, 2019 5:30 pm

Switched to LibreOffice 6.2.

It works perfectly fine now.

Thanks
LibreOffice 6.2
gurkand
 
Posts: 18
Joined: Wed Feb 28, 2018 10:27 am


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests