Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4   7.5    Statistic  

XL.Book.DeleteSheet

Deletes a sheet with specified index.

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
XL 3.5 Yes Yes Yes Yes Yes

MBS( "XL.Book.DeleteSheet"; bookRef; sheetIndex )

Parameters

Parameter Description Example value
bookRef The reference to the workbook. Please use XL.LoadBook to load a file. $ref
sheetIndex The index of the sheet to delete. This number ranges from 0 to XL.Book.SheetCount-1. 0

Result

Returns OK on success.

Description

Deletes a sheet with specified index.
If the sheet to delete is referenced by other sheets, this may cause problems.

Examples

Remove all sheets but the second one:

#Find libXL and load it
If [MBS("XL.IsInitialized") ≠ 1]
    Perform Script [“InitXL”]
End If
#Load template excel file
Set Variable [$bookRef; Value:MBS( "XL.LoadBook"; "/Users/cs/Desktop/Test.xlsx")]
If [MBS("IsError")]
    Show Custom Dialog ["Error"; $bookRef]
    Exit Script []
End If
#remove all but second sheet
Set Variable [$c; Value:MBS( "XL.Book.SheetCount"; $bookRef )]
If [$c >= 2]
    If [$c > 2]
        Set Variable [$i; Value:2]
        Loop
            Set Variable [$r; Value:MBS( "XL.Book.DeleteSheet"; $bookRef; $i )]
            Set Variable [$i; Value:$i + 1]
            Exit Loop If [$c = $i]
        End Loop
    End If
    Set Variable [$r; Value:MBS( "XL.Book.DeleteSheet"; $bookRef; 0 )]
End If
#Save to container and cleanup
Set Variable [$r; Value:MBS("XL.Book.SaveToFile"; $bookRef; "/Users/cs/Desktop/output.xlsx")]
Set Variable [$r; Value:MBS( "XL.Book.Release"; $bookRef)]

See also


XL.Book.CustomNumFormat   -   XL.Book.DeleteSheetsExcept

Feedback: Report problem or ask question.




Links
MBS Xojo Chart Plugins