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

CREATE OBJECT h_excel 'EXCEL.APPLICATION'.

Former Member
0 Likes
3,543

hi all!

I need know, what method or property i have to use, for set up the filename by default, for the workbook that i created.

thank in advance

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,654

You assign the file name when you save the file.

For example......




data: e_sheet type ole2_object.
data: e_appl  type ole2_object.
data: e_work  type ole2_object.
data: e_cell  type ole2_object.
data: e_wbooklist type ole2_object.

parameters: p_file type localfile default 'C:Test.xls'.

start-of-selection.


* Start the application
  create object e_appl 'EXCEL.APPLICATION'.
  set property of e_appl 'VISIBLE' = 0.

* Open the file
  call method of e_appl 'WORKBOOKS' = e_wbooklist.
  get property of e_wbooklist 'Application' = e_appl .
  set property of e_appl 'SheetsInNewWorkbook' = 1 .
  call method of e_wbooklist 'Add' = e_work .
  get property of e_appl 'ActiveSheet' = e_sheet .
  set property of e_sheet 'Name' = 'Test' .


* Position to specific cell  in  Column 1
    call method of e_appl 'Cells' = e_cell
           exporting
                #1 = 1
                #2 = 1.
* Set the value
    set property of e_cell 'Value' = 'ABC'.




** Close the file
  get property of e_appl 'ActiveWorkbook' = e_work.
  call method of e_work 'SAVEAS'
        exporting
            #1 = p_file
            #2 = 1  .        " Don't ask me when closing
  
  call method of e_work 'close'.

Regards,

Rich Heilman

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,655

You assign the file name when you save the file.

For example......




data: e_sheet type ole2_object.
data: e_appl  type ole2_object.
data: e_work  type ole2_object.
data: e_cell  type ole2_object.
data: e_wbooklist type ole2_object.

parameters: p_file type localfile default 'C:Test.xls'.

start-of-selection.


* Start the application
  create object e_appl 'EXCEL.APPLICATION'.
  set property of e_appl 'VISIBLE' = 0.

* Open the file
  call method of e_appl 'WORKBOOKS' = e_wbooklist.
  get property of e_wbooklist 'Application' = e_appl .
  set property of e_appl 'SheetsInNewWorkbook' = 1 .
  call method of e_wbooklist 'Add' = e_work .
  get property of e_appl 'ActiveSheet' = e_sheet .
  set property of e_sheet 'Name' = 'Test' .


* Position to specific cell  in  Column 1
    call method of e_appl 'Cells' = e_cell
           exporting
                #1 = 1
                #2 = 1.
* Set the value
    set property of e_cell 'Value' = 'ABC'.




** Close the file
  get property of e_appl 'ActiveWorkbook' = e_work.
  call method of e_work 'SAVEAS'
        exporting
            #1 = p_file
            #2 = 1  .        " Don't ask me when closing
  
  call method of e_work 'close'.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,654

try this

DATA: o_application TYPE ole2_object,

o_workbook TYPE ole2_object,

o_worksheet TYPE ole2_object,

o_sheet TYPE ole2_object.

PARAMETERS: p_excel TYPE rlgrap-filename DEFAULT 'C:\Soft\Book1.xls',

p_sheet(30) TYPE c DEFAULT 'Sheet2'.

START-OF-SELECTION.

CREATE OBJECT o_application 'Excel.Application'.

CALL METHOD OF o_application 'Workbooks' = o_workbook.

CALL METHOD OF o_workbook 'Open' EXPORTING #1 = p_excel.

CALL METHOD OF o_application 'WORKSHEETS' = o_sheet EXPORTING #1 = p_sheet.

CALL METHOD OF o_sheet 'DELETE'.

CALL METHOD OF o_workbook 'Save'.

CALL METHOD OF o_application 'Save'.

FREE OBJECT: o_application, o_workbook, o_worksheet, o_sheet.

Please reward if useful.

Read only

Former Member
0 Likes
1,654

thanks very much

The answers have been help full for me.

best regards