Basic Macro to test if open document is a spreadsheet

I created a macro to autofit a spreadsheet that is imported from a CVS file. But need the syntax to do the
following logic

If Open document is a spreadsheet then
do code
else
do nothing
or
If open document is a CSV format then
do code
else do nothing

Thanks

Does “is a spreadsheet” mean that the file has been saved as .ods or .xlsx or similar, and not .csv?

Hello @dickm,

Please try if the following:

Function dummy()
	Dim oDoc As Object	: oDoc = ThisComponent		REM The current document.
	If oDoc.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) Then
		REM it is a Spreadsheet ( also includes CSV opened in Calc ):
		msgbox "'do code"
	Else
		'do nothing'
	End If
End Function

Hi @librebel - I just added the quote at the end of the line comment (obviously useless in basic but necessary here)

Merci @Pierre-Yves, i have to remember to do that from now on…

A CSV file becomes a spreadsheet when it is opened in Calc. It sounds like you are asking about the file format instead.

Sub WhatFileType
    sURL = ThisComponent.getURL()
    strings = Split(sURL, ".")
    extension = strings(UBound(strings))
    MsgBox "File Type is " & extension
End Sub