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

Opening Excel Spreadsheet from ABAP

Former Member
0 Likes
2,858

Hello,

Is there any way to put data from an ABAP program into an existing Excel spreadsheet? I know how to put the data into a new spreadsheet but my users want to put the data into an existing spreadsheet where they have developed macros.

Thanks,

Becky

1 ACCEPTED SOLUTION
Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
1,580

Hi Becky

Here is a procedure using OLE automation.


DATA gs_excel TYPE ole2_object .
DATA gs_wbooks TYPE ole2_object .
DATA gs_wbook TYPE ole2_object .
DATA gs_application TYPE ole2_object .

CREATE OBJECT gs_excel 'EXCEL.APPLICATION' .
SET PROPERTY OF gs_excel 'Visible' = 1 .
GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooks .
GET PROPERTY OF gs_wbooks 'Application' = gs_application .

*--Opening the existing document
CALL METHOD OF gs_wbooks 'Open' = gs_wbook
     EXPORTING #1 = <file_path_var> .

"*--After this point you can go on processing the sheet
using OLE Automation techniques"

If it is just the template to be stored you can save the template .xls file at the application server each time downloading it to a temporary place to open. Or you can store it at SAP Office templates folder. For SAP Office operations you can inspect "BC_SO_*" masked FMs.

And as a last thing, let me introduce you the SDN forums pointing system: You can assign points to posts you find helpful while solving your question. You can reward points by clicking the yellow star icon at header of each reply post. You can reward;

- one 10 points (solved)

- two 6 points (very helpful answer)

- many 2 points (helpful answer)

Kind Regards...

*--Serdar

Hi Becky

Here is a procedure using OLE automation.


DATA gs_excel TYPE ole2_object .
DATA gs_wbooks TYPE ole2_object .
DATA gs_wbook TYPE ole2_object .
DATA gs_application TYPE ole2_object .

CREATE OBJECT gs_excel 'EXCEL.APPLICATION' .
SET PROPERTY OF gs_excel 'Visible' = 1 .
GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooks .
GET PROPERTY OF gs_wbooks 'Application' = gs_application .

*--Opening the existing document
CALL METHOD OF gs_wbooks 'Open' = gs_wbook
     EXPORTING #1 = <file_path_var> .

"*--After this point you can go on processing the sheet
using OLE Automation techniques"

If it is just the template to be stored you can save the template .xls file at the application server each time downloading it to a temporary place to open. Or you can store it at SAP Office templates folder. For SAP Office operations you can inspect "BC_SO_*" masked FMs.

And as a last thing, let me introduce you the SDN forums pointing system: You can assign points to posts you find helpful while solving your question. You can reward points by clicking the yellow star icon at header of each reply post. You can reward;

- one 10 points (solved)

- two 6 points (very helpful answer)

- many 2 points (helpful answer)

Kind Regards...

*--Serdar

7 REPLIES 7
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,580

You are going to want to look into OLE2 controls.

Check demo program RSDEMO01. I am using 46c.

Good luck,

Rich Heilman

Read only

Former Member
0 Likes
1,580

Hi Rebecca,

you can open the Excel file in append mode, that will help you to retain the previous entries. Then in case of the Macro, i am not sure about that, if i find anything i will let you know.

Regards,

Kathirvel.

Read only

ssimsekler
Product and Topic Expert
Product and Topic Expert
0 Likes
1,581

Hi Becky

Here is a procedure using OLE automation.


DATA gs_excel TYPE ole2_object .
DATA gs_wbooks TYPE ole2_object .
DATA gs_wbook TYPE ole2_object .
DATA gs_application TYPE ole2_object .

CREATE OBJECT gs_excel 'EXCEL.APPLICATION' .
SET PROPERTY OF gs_excel 'Visible' = 1 .
GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooks .
GET PROPERTY OF gs_wbooks 'Application' = gs_application .

*--Opening the existing document
CALL METHOD OF gs_wbooks 'Open' = gs_wbook
     EXPORTING #1 = <file_path_var> .

"*--After this point you can go on processing the sheet
using OLE Automation techniques"

If it is just the template to be stored you can save the template .xls file at the application server each time downloading it to a temporary place to open. Or you can store it at SAP Office templates folder. For SAP Office operations you can inspect "BC_SO_*" masked FMs.

And as a last thing, let me introduce you the SDN forums pointing system: You can assign points to posts you find helpful while solving your question. You can reward points by clicking the yellow star icon at header of each reply post. You can reward;

- one 10 points (solved)

- two 6 points (very helpful answer)

- many 2 points (helpful answer)

Kind Regards...

*--Serdar

Read only

0 Likes
1,580

Hi

I'm using the same technique to run a macro in excel which selects a tab to become active.

However, I need it to save excel & return to SAP, but I'm left in Excel. Do you know how to do this please?

Thanks

Sunni

Read only

0 Likes
1,580

Pls also check Thomas Jung Weblogs

/people/thomas.jung3/blog/2005/02/14/bsp-and-microsoft-excel--learning-to-live-together

/people/thomas.jung3/blog/2005/02/23/bsp-and-microsoft-excel--learning-to-live-together-part-2

Read only

0 Likes
1,580

The code is below, it leaves me in Excel after running the macro rather than returning to my ABAP??

DATA gs_excel TYPE ole2_object .

DATA gs_wbooks TYPE ole2_object .

DATA gs_wbook TYPE ole2_object .

DATA gs_application TYPE ole2_object .

CREATE OBJECT gs_excel 'EXCEL.APPLICATION' .

SET PROPERTY OF gs_excel 'Visible' = 1 .

GET PROPERTY OF gs_excel 'Workbooks' = gs_wbooks .

GET PROPERTY OF gs_wbooks 'Application' = gs_application .

*--Opening the existing document

CALL METHOD OF gs_wbooks 'Open' = gs_wbook

EXPORTING #1 = 'C:\BOOK1.XLS'.

CALL METHOD OF GS_EXCEL 'RUN' EXPORTING #1 = 'MACRO4'.

FREE OBJECT EXCEL.

???

Read only

0 Likes
1,580

Sunni,

may I ask you how do you define your 'MACRO4'?

Is this excel macro or ABAP macro?

Thanks,

Maria