XLS Open Error S_OK

XLS Open Error S_OK

Postby cdmmaui » Sun Apr 14, 2013 3:23 pm

Hello,

I am using the following code to open XLS and I am getting ERROR READING XLS: cdm2013.xls - [S_OK]. Do I need to open XLS differently? I have MS Office Professional Plus 2010.

TRY
oExcel := GetActiveObject( "Excel.Application" )
CATCH
TRY
oExcel := CreateObject( "Excel.Application" )
CATCH
Alert( "Cannot Connect to Excel. [" + Ole2TxtError()+ "]" )
RETURN (.T.)
END
END

// Open XLS...
TRY
oExcel:WorkBooks:Open( cSource ) // Also tried oExcel:WorkBooks:Open( cSource, OleDefaultArg(), OleDefaultArg(), OleDefaultArg() )
oSheet = oExcel:ActiveSheet
CATCH
Alert( "Error Reading XLS: " + cSource + " - [" + Ole2TxtError()+ "]" )
RETURN (.F.)
END

Image
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong

Re: XLS Open Error S_OK

Postby Rick Lipkin » Sun Apr 14, 2013 3:54 pm

Darrell

This code has always worked for me .. I have not tried this on Excel 2010-2013 ..

Code: Select all  Expand view

Try
   oEXCEL := TOleAuto():New( "Excel.Application" )
Catch
   Saying := "Error in Opening Excel object"+chr(10)
   Saying += "Make sure you have MS Excel loaded on your Computer"+chr(10)
   MsgInfo( Saying )
   Return(.f.)
End Try

Try
   oExcel:Workbooks:Open( cPATH )      // cpath includes the path and excel file name
Catch
   Saying := "Error in Opening Excel Workbook"
   MsgInfo( Saying )
   Return(.f.)
End Try

oBook := oExcel:Get( "ActiveSheet" )

 


Hope this helps
Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2665
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: XLS Open Error S_OK

Postby cdmmaui » Sun Apr 14, 2013 4:02 pm

Thanks Rick, having the full path of XLS resolved the problem. I appreciate your quick response.
*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
User avatar
cdmmaui
 
Posts: 689
Joined: Fri Oct 28, 2005 9:53 am
Location: Houston ∙ Chicago ∙ Los Angeles ∙ Miami ∙ London ∙ Hong Kong


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Antonio Linares, Google [Bot] and 94 guests