ScriptForge.CreateScriptService("Calc") always returns Null. Need a sample

Hello, All. I’m trying to use ScriptForge in a Basic module, stored in a Calc document.
I’ve assigned a macro to the button on a sheet. A macro calls this sub (InitSheets).

Const DATA_SHEET_NAME = "Data"

Public oChartSheet as Object
Public oDataSheet as Object
Public iLastFilledRow as Integer

Sub InitSheets
	'This finds document, sheets, and filled data range
	If GlobalScope.BasicLibraries.hasByName("ScriptForge") Then 
	 	MsgBox ("Library ScriptForge is missing!", MB_ICONEXCLAMATION + MB_OK, "Warning Message")
	 	Exit Sub
	End If

	Dim oDocument as Object
	oDocument = ScriptForge.CreateScriptService("SFDocuments.Calc")  'Null anyway :-(
	'oDocument = ScriptForge.CreateScriptService("Calc")
	if oDocument.IsCalc Then
		oChartSheet = oDocument.getActiveSheet()
		oDataSheet = oDocument.Sheet(DATA_SHEET_NAME)
		iLastFilledRow = LastRow(DATA_SHEET_NAME)
	End If
End Sub

The problem is that oDocument is always Null after CreateScriptService call. What do I miss here?
It would be nice to see any working code example, which returns this Calc service for current open document.

oDoc = CreateScriptService("Calc", ThisComponent)

Screenshot from 2024-06-15 10-21-25

see details from SFDocuments.Calc service

1 Like

its amazing :persevere:
previously one line would have been needed:

doc = thisComponent

Wow. That simple! Thank you.
It’s good that at least one of invocations works! Ironically, the last one in the list :slight_smile:

Progress never stops. One-liners are too boring… :slight_smile:
But … what about a one-liner like the last line in the pic above (oDoc.DSum("~.A1:A10"))? :wink: