BASIC+Calc: How to Freeze Rows and Columns

From this post, I have edited in order to freeze on a specific Sheet and it is not an active Sheet.

Dim oDoc As Object
oDoc = ThisComponent
oDoc.CurrentController.FreezeAtPosition(0,6)

It freezed on the active Sheet.

Can you please help me freeze on a specific Sheet which is not an active Sheet ?

This option, have sense only in visible sheet, so, you can apply when activate or activate and return to current activate sheet.

doc = ThisComponent
cc = doc.CurrentController
current = cc.Selection
sheet = doc.Sheets(0)
cc.select(sheet)
cc.freezeAtPosition(5,5)
cc.select(current)

@mauricio

Thank you so much for code and your explanation.

.

Sub FreezeRowsColumns
    TCCC = ThisComponent.CurrentController 
    TCCC.select( ThisComponent.getSheets.getByName( "Plan2" )
    TCCC.freezeAtPosition(6,5)
    TCCC.select(current)
    End sub

@mauricio

Sub FreezePane
'	Dim doc As Object : doc = ThisComponent
'	Dim cc As Object : cc = doc.CurrentController
'	Dim current As Object : current = cc.Selection
	Dim current As Object : current = ThisComponent.CurrentController.Selection
	ThisComponent.Sheets(0) 'Dim sheet As Object : sheet = doc.Sheets(0)
	ThisComponent.CurrentController.Select(ThisComponent.Sheets(0))	'cc.Select(sheet)
	ThisComponent.CurrentController.FreezeAtPosition(5,5) 'cc.FreezeAtPosition(5,5)
	ThisComponent.CurrentController.Select(current)	'cc.Select(current)
End Sub

Is it possible to avoid variable namely ‘current’ ?

I don’t understand, “avoid”, you need save your reference to current sheet in some place if you want return after, but… that large lines are ugly for me.

.This one has freezing it removes and if it has no places.

sub FreezeRowsColumns2
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint" : args1(0).Value = "Plan1.$B$7"
createUnoService("com.sun.star.frame.DispatchHelper").executeDispatch(ThisComponent.CurrentController.Frame, ".uno:GoToCell", "", 0, args1())
createUnoService("com.sun.star.frame.DispatchHelper").executeDispatch(ThisComponent.CurrentController.Frame, ".uno:FreezePanes", "", 0, Array())
end Sub

@mauricio

Thank you so much for your explanation.
So, that variable is for keeping the initial location.

And sorry for my long and disgusting code. This week I have just started learning LO BASIC after breaking up with MS Excel VBA which I have ever used for decades.

If you started with macros in LibreOffice, I recommended you start with Python, not Basic. Best regards.

P.S. Many year ago, I wrote macros in VBA too.

Dear @mauricio ,

Thank you so much for your concern.

After finishing my project on LO BASIC Calc, I will learn LO Python Calc.

Now many people are heading for LO Python Calc.

Can you please tell me why they prefer LO Python Calc in brief?

Where finish Basic, barely start Python.