MoveSheet

Description: Move a sheet to a new location within a workbook.

Parameters:

MoveSheet(sPathOriginal As String, sPathTarget As String, sSheetToMove As String, sSheetBefore As String, sSheetAfter As String) As Long

Parameter

Meaning

sPathOriginal

Excel file within which the sheet will be moved.

sPathTarget

Can be same as sPathOriginal, otherwise a new workbook is created.

sSheetToMove

Name of the sheet to move. Can be a name or #.

sSheetBefore

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

sSheetAfter

Sheet will be placed after this sheet (Name or #). If sSheetAfter = "lastlast" then it is placed as the last sheet. NOTE: If both sSheetBefore and sSheetAfter are empty, then the sheet will be moved to the last position.

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 

-215: Sheet to move does not exist 

Example Code:

Taken from the sample VB program provided, a form is displayed to collect necessary data, which is then passed to the component for processing by the MoveSheet() function of the component.

Case SP_XLS_MOVE_SHEET

frmXLSMoveSheet.Show vbModal 'display the form

If (frmXLSMoveSheet.bErrorOccurred = True) Then

Exit Sub 'check for error

Else 'collect necessary data

strSheetToMove = frmXLSMoveSheet.sSheetToMove

strSheetBefore = frmXLSMoveSheet.sSheetBefore

strSheetAfter = frmXLSMoveSheet.sSheetAfter

End If

  'call the component with necessary arguments

lngResult = XLSConv1.MoveSheet(strSourceFile,

strTargetFile, strSheetToMove,

strSheetBefore, strSheetAfter)

Unload frmXLSMoveSheet