DeleteSheet

Description: Delete a sheet or range of sheets within a workbook. Due to Excel limitations, at least one sheet must remain in a workbook at all times.

Parameters:

DeleteSheet(sPathOriginal As String, sPathTarget As String, sSheetStart As String, sSheetEnd As String, sSheetExcept As String) As Long

Parameter

Meaning

SPathOriginal

Excel file from which to delete sheet(s).

SSheetOriginal

Sheet Name or number to delete.

SPathTarget

Can be same as sPathOriginal, otherwise a new workbook is created containing only the remaining sheets, leaving sPathOriginal unchanged.

SSheetStart

Used to either specify the deletion of a single sheet, or the beginning of a range of sheets to delete. Note: the range is inclusive, meaning sSheetStart is deleted.

SSheetEnd

Used to specify the end of a range of sheets to delete. Note: the range is inclusive, meaning sSheetEnd is deleted.

SSheetExcept

Used to specify the only sheet to remain in the workbook. All other sheets will be deleted. NOTE: If sSheetExcept is not specified, sSheetStart must be. If not -213 is returned.

Return Values:

0: Success 

-3: Unable to create Excel Application. Is it installed? 

-4: Unable to destroy Excel Application. 

-200: Excel reported an error 

-201: Shareware Expired 

-208: Target Path folder does not exist, even after attempting to create it. 

-213: Invalid or missing sheets specified 

Example Code:

Taken from the sample VB program, this code snippet demonstrates the collection of data, which is then passed to the component when DeleteSheet() is called.

Case SP_XLS_DELETE_SHEET

frmXLSDeleteSheet.Show vbModal 'display data collection form

If (frmXLSDeleteSheet.bErrorOccurred = True) Then

Exit Sub    'check for error

Else  'collect the necessary data

strSheetStart = frmXLSDeleteSheet.sSheetStart

strSheetEnd = frmXLSDeleteSheet.sSheetEnd

strSheetExcept = frmXLSDeleteSheet.sSheetExcept

End If

  'call the component with necessary arguments

lngResult = XLSConv1.DeleteSheet(strSourceFile, strTargetFile,

strSheetStart, strSheetEnd, strSheetExcept)