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
GlobalScope.BasicLibraries.LoadLibrary("ScriptForge")
Else
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.