FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour XLS Open Error S_OK
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
XLS Open Error S_OK
Posted: Sun Apr 14, 2013 03: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

*~*~*~*~*~*~*~*~*~*
Darrell Ortiz
CDM Software Solutions, Inc.
https://www.cdmsoft.com
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: XLS Open Error S_OK
Posted: Sun Apr 14, 2013 03:54 PM
Darrell

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

Code (fw): Select all Collapse
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
Posts: 708
Joined: Fri Oct 28, 2005 09:53 AM
Re: XLS Open Error S_OK
Posted: Sun Apr 14, 2013 04: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

Continue the discussion