Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

OLE Method SAVEAS

Former Member
0 Likes
3,653

Hi,

I am using OLE to open and save an excel file in a different format. But the code is not working.

This is the code I am using:


INCLUDE ole2incl.

DATA file_in TYPE rlgrap-filename.
DATA file_out TYPE rlgrap-filename.

DATA excel TYPE ole2_object.
DATA workbook TYPE ole2_object.

file_in = 'C:\Read.xls'.
file_out = 'C:\Write.csv'.

CREATE OBJECT excel 'Excel.Application'.
IF sy-subrc NE 0.
  WRITE: / 'No EXCEL creation possible'.
  STOP.
ENDIF.

CALL METHOD OF excel 'WORKBOOKS' = workbook.

CALL METHOD OF workbook 'Open' EXPORTING #1 = file_in.


CALL METHOD OF workbook 'SAVEAS' EXPORTING #1 = file_out #2 = '6'.
CALL METHOD OF workbook 'CLOSE'.
CALL METHOD OF excel 'QUIT'.

* Code errors out here with sy-subrc = 2
IF sy-subrc <> 0.
  WRITE: / 'OLE ERROR: RETURN CODE ='(i10), sy-subrc.
  STOP.
ENDIF.

FREE OBJECT workbook.
FREE OBJECT excel.

Please help me out solve this one,

Thanks,

CD

1 REPLY 1
Read only

former_member189059
Active Contributor
0 Likes
1,407

Hello.. try this


INCLUDE ole2incl.

DATA file_in TYPE rlgrap-filename.
DATA file_out TYPE rlgrap-filename.

DATA excel TYPE ole2_object.
DATA workbook TYPE ole2_object.
DATA SHEET TYPE ole2_object. "changed

file_in = 'C:\it_results.xls'.
file_out = 'C:\Write.csv'.

CREATE OBJECT excel 'Excel.Application'.
IF sy-subrc NE 0.
  WRITE: / 'No EXCEL creation possible'.
  STOP.
ENDIF.

CALL METHOD OF excel 'WORKBOOKS' = workbook.

CALL METHOD OF workbook 'Open' EXPORTING #1 = file_in.

GET PROPERTY OF excel 'ActiveSheet' = sheet.  " changed
CALL METHOD OF sheet 'SaveAs' EXPORTING #1 = file_out #2 = 6. " changed
CALL METHOD OF workbook 'CLOSE'.
CALL METHOD OF excel 'QUIT'.

* Code errors out here with sy-subrc = 2
IF sy-subrc NE 0.
  WRITE: / 'OLE ERROR: RETURN CODE ='(i10), sy-subrc.
  STOP.
ENDIF.

FREE OBJECT workbook.
FREE OBJECT excel.