Why can't the compiler find the method getActiveSheet?

Hello,

On LibreOffice 3.6.2.2 on Linux Mint 14, I try to use

Dim oActiveSheet As Variant
oActiveSheet = ThisComponent.getCurrentController().getActiveSheet()

But when I launch it, the compiler says me that he can find the methode or property getActiveSheet.

How can I correct this?

Thank you

Where do you launch your macro? From what? From sheet of workbook or from basic IDE? What component basic get as ThisComponent?

After some test, the command works. I just comment and uncomment “Option Explicit”.
Thanks you for your help

Miracle on the level of shamanism :slight_smile:

@Primomh – could you please turn your comment into an Answer so we could use it to resolve this question? (As @JohnSUN notes, the solution does seem a bit like black magic, but if that’s what fixed it… :slight_smile:

Thanks!

Please, try this code:

Sub testDocType
Dim oDoc
Dim docType$
Dim oSheet
	oDoc = ThisComponent
	GlobalScope.BasicLibraries.LoadLibrary("Tools")
	docType = GetDocumentType(oDoc) 
	print "Now 'ThisComponent' is '"+docType+"'"
	If docType<>"scalc" Then Exit Sub
	oSheet = oDoc.getCurrentController().getActiveSheet()
	print "Name of Active Sheet is '"+oSheet.getName()+"'"
End Sub

See comment of the first post for the answer

(Comment → Answer for resolution)

Primomh notes:

After some test, the command works. I just comment and uncomment “Option Explicit”.
Thanks you for your help