OpenXLSSaveAs

Description: Performs the conversion of an Excel, CSV or any file Excel can open into any of the file formats Excel can Save As.

Parameters:

OpenXLSSaveAs(sSourceFile As String, sSheets As String, sTargetFile As String, lTargetType As Long, bDoFormula As Boolean) As Long

Parameter

Meaning

sSourceFile

The file to be converted. It can be any file Excel can open. When installing MS Office, be sure to install all the Text and file filters available.

sTargetFile

Name for file resulting from the conversion process.

sSheets

Name or index number of sheet(s) being converted. You can specify single or multiple sheets, by name or index number.

lTargetType

The file format to convert TO, i.e. the format sTargetFile will be saved as. See Excel File Conversion Formats for valid values. FilesJustCreated

bDoFormula

If TRUE, OpenXLSSaveAs() will convert the formula rather than the value of each cell.

Return Values:

0 = Success 

-2 = Source file does not exist 

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

-4 = Unable to destroy Excel Application. 

-10 = General Excel Error, see ErrorString for details 

-11 = Invalid Sheet Specified 

-201 = Shareware expired 

Example Code:

Taken from the sample VB program provided, the necessary arguments are passed to the function OpenXLSSaveAs() in this case.

Private Function PerformConversionXLS(strSourceFile As String, _

strSheets As String, _

strTargetFile As String, _

lngTargetType As Long, _

blnDoFormula As Boolean) As Long

Dim lngConvResult As Long

 'call the component with necessary arguments

lngConvResult = XLSConv1.OpenXLSSaveAs(strSourceFile, strSheets,

   strTargetFile, lngTargetType, blnDoFormula)

 'check that a file was created

If (lngConvResult = 0) Then

If (FileExists(strTargetFile) = False) Then

lngConvResult = -100

End If

End If

 'assign an error code, if applicable

Select Case (lngConvResult)

Case -2

strErr = "Source file does not exist."

Case -3

strErr = "Unable to create Excel Application. Is it

installed?"

Case -4

strErr = "Unable to destroy Excel Application."

Case -10

strErr = "General Excel error."

Case -100

strErr = "File does not exist."

End Select

 

'function value returned to caller for additional evaluation

PerformConversionXLS = lngConvResult

End Function