[Solved] Sheet active (visible) in VB.NET

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
felixjm
Posts: 5
Joined: Mon Jun 13, 2022 5:34 am

[Solved] Sheet active (visible) in VB.NET

Post by felixjm »

I have an ODS saved with tab 0 active.
What command in VB.NET makes another tab active (visible)?
Last edited by Hagar Delest on Mon Jun 13, 2022 8:17 pm, edited 1 time in total.
Reason: tagged solved.
OpenOffice 3.1 on Windows Vista
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Sheet active (visible) in VB.NET

Post by Zizi64 »

Do you want to create AOO/LO Macros? That uses the API and (mostly) the StarBasic. You can control the application by the API functions from other developing environments, but not by any VB.NET "commands". You must study the API functions of the AOO and LO.

API: Application Programming Interface
LO: LibreOffice
AOO: Apache OpenOffice
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Sheet active (visible) in VB.NET

Post by Zizi64 »

____________________________________
OpenOffice 3.1 on Windows Vista
What software and version are you using really? AOO or LO? Please update your signature in this Forum.
Last edited by Zizi64 on Mon Jun 13, 2022 4:24 pm, edited 1 time in total.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
JeJe
Volunteer
Posts: 2763
Joined: Wed Mar 09, 2016 2:40 pm

Re: Sheet active (visible) in VB.NET

Post by JeJe »

Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
felixjm
Posts: 5
Joined: Mon Jun 13, 2022 5:34 am

Re: Sheet active (visible) in VB.NET

Post by felixjm »

I'm using LibreOffice 6.0 and VB.NET Express 2019.

Test the code below and it didn't work. Have another tip?

Dim oSM 'Root object for accessing OpenOffice from VB
Dim oDesk, oDoc As Object 'First objects from the API
Dim arg(1) As Object 'Used as parameter in opening doc
Dim LCSV1, LCSVX, LXXX() As String
'
Dim FILECSV As String = "D:\TESTEX.CSV"
Dim FILEODS As String = "D:\TESTEX.ODS"
'
oSM = CreateObject("com.sun.star.ServiceManager") 'Instantiate Open Office for VB
oDesk = oSM.createInstance("com.sun.star.frame.Desktop") 'Create service
oDoc = oDesk.loadComponentFromURL("file:///" & Replace(FILEODS, "\", "/"), "_blank", 0, arg) 'Open an existing doc, note no index on arg parameter
'
FileOpen(1, FILECSV, Microsoft.VisualBasic.OpenMode.Input)
LCSV1 = LineInput(1)
LXXX = LCSV1.Split(CType(";", Char()))
'
Dim oSheet0 As Object
oSheet0 = oDoc.getSheets().getByIndex(0) 'Get first sheet
Dim B6 As String = Mid(LXXX(1), 4)

Call oSheet0.getCellByPosition(1, 5).SetString(B6)
'
Dim X As Integer = Int(Mid(LXXX(0), 3))
Dim oSheetX As Object
oSheetX = oDoc.getSheets().getByIndex(X) 'Get sheet perimetro_x
'
oSheet0.IsVisible = True '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
oSheet0.IsActive = True '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'
Dim LL As Integer = 11
While Not EOF(1)
LCSVX = LineInput(1)
LXXX = LCSVX.Split(CType(";", Char()))
Call oSheetX.getCellByPosition(0, LL).SetString(LXXX(0)) 'Enter string value in selected cells(Col, Row) 'Cell Entry Options – SetValue(123) SetString(“ABC”) SetFormula(“=SUM(A1:E4)”)
Call oSheetX.getCellByPosition(1, LL).SetString(LXXX(1))
Call oSheetX.getCellByPosition(2, LL).SetString(LXXX(2))
Call oSheetX.getCellByPosition(3, LL).SetString(LXXX(3))
Call oSheetX.getCellByPosition(4, LL).SetString(LXXX(4))
Call oSheetX.getCellByPosition(5, LL).SetString(LXXX(5))
Call oSheetX.getCellByPosition(6, LL).SetString(LXXX(6))
Call oSheetX.getCellByPosition(7, LL).SetString(LXXX(7))
Call oSheetX.getCellByPosition(8, LL).SetString(LXXX(8))
Call oSheetX.getCellByPosition(9, LL).SetString(LXXX(9))
Call oSheetX.getCellByPosition(10, LL).SetString(LXXX(10))
Call oSheetX.getCellByPosition(11, LL).SetString(LXXX(11))
LL = LL + 1
End While
FileClose(2)
'
'Save the doc
Call oDoc.store()
'
MsgBox(“Program Finished”)
OpenOffice 3.1 on Windows Vista
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Sheet active (visible) in VB.NET

Post by Villeroy »

That code should work no matter which sheet is visible. It writes to the first sheet.

Code: Select all

 oSheet0 = oDoc.getSheets().getByIndex(0) 'Get first sheet
Change the sheet index if you want to write to any other sheet.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
felixjm
Posts: 5
Joined: Mon Jun 13, 2022 5:34 am

Re: Sheet active (visible) in VB.NET

Post by felixjm »

This code informed is already in my program and is working.

What I need is for the tab being recorded to be visible to the user.
OpenOffice 3.1 on Windows Vista
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Sheet active (visible) in VB.NET

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
felixjm
Posts: 5
Joined: Mon Jun 13, 2022 5:34 am

Re: Sheet active (visible) in VB.NET

Post by felixjm »

What is not working is the following code.
oSheet0.IsVisible = True '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
oSheet0.IsActive = True '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
OpenOffice 3.1 on Windows Vista
FJCC
Moderator
Posts: 9248
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Sheet active (visible) in VB.NET

Post by FJCC »

In OpenOffice Basic

Code: Select all

oDoc.CurrentController.setActiveSheet(oSheet0)
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.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Sheet active (visible) in VB.NET

Post by Villeroy »

felixjm wrote: Mon Jun 13, 2022 3:19 pm What is not working is the following code.
oSheet0.IsVisible = True '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
oSheet0.IsActive = True '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
FOR HEAVENS SAKE, WE ARE NOT HUMAN MACRO RECORDERS!
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
felixjm
Posts: 5
Joined: Mon Jun 13, 2022 5:34 am

Re: Sheet active (visible) in VB.NET

Post by felixjm »

oDoc.CurrentController.setActiveSheet(oSheet0)
Excellent, perfect, it worked.

Very grateful to everyone.

OK.
OpenOffice 3.1 on Windows Vista
Post Reply