AddSheet

Description: Add a new blank worksheet to a specified location within a workbook.

Parameters:

AddSheet(sPathOriginal As String, sPathTarget As String, sSheetToAdd As String, sSheetBefore As String, sSheetAfter As String, bOverwrite As Boolean) As Long

Parameter

Meaning

sPathOriginal

Excel file to use as the original file.

sPathTarget

Can be same as sPathOriginal, otherwise a new workbook is created with both the original and newly added sheet(s).

sSheetToAdd

Name of the sheet to add. Not required, can use "" to get default Excel name.

sSheetBefore

Added sheet will be placed before this sheet (Name or #). If sSheetBefore = "firstfirst" then it is placed as the first sheet in the workbook.

sSheetAfter

Added sheet will be placed after this sheet (Name or #). If sSheetAfter = "lastlast" then it is placed as the last sheet.

bOverwrite

If sSheetToAdd already exists, it will be overwritten if this parameter is set to TRUE. Otherwise error -212 is returned.

Notes: If both sSheetBefore and sSheetAfter are empty strings then the new sheet will be the last sheet.

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 

-204: Source Sheet does not exist 

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

-210: SheetBefore or SheetAfter does not exist 

-212: "Target Sheet already exists. Set overwrite to TRUE to copy over existing sheet." 

Example Code:

Taken from the sample VB program provided, when AddSheet() is called, a data collection form is displayed, the data is collected then passed to the component for processing.

Case SP_XLS_ADD_SHEET

frmXLSAddSheet.Show vbModal 'display form

If (frmXLSAddSheet.bErrorOccurred = True) Then

Exit Sub

Else 'collect necessary data

strSheetToAdd = frmXLSAddSheet.sTargetSheet

strSheetBefore = frmXLSAddSheet.sSheetBefore

strSheetAfter = frmXLSAddSheet.sSheetAfter

blnOverwrite = frmXLSAddSheet.bOverwrite

End If

  'call component with necessary arguments

lngResult = XLSConv1.AddSheet(strSourceFile, strTargetFile,

strSheetToAdd, strSheetBefore, strSheetAfter,

blnOverwrite)