Application Development 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: 

Unable to close Excel

Former Member
0 Kudos

Hello everyone

I have written code like this

   

CREATE OBJECT EXCEL 'EXCEL.APPLICATION'.
CALL METHOD OF EXCEL 'WORKBOOKS' = FILE.

  CALL METHOD OF FILE 'OPEN'
    EXPORTING
      #1 = 'C:temp8D.xls'
      #2 = 1.

  CALL METHOD OF EXCEL 'CELLS' = CELL
    EXPORTING
      #1 = 6
      #2 = 'C'.
  SET PROPERTY OF CELL 'VALUE' = zak_help.

CALL METHOD OF EXCEL 'CELLS' = CELL
    EXPORTING
      #1 = 7
      #2 = 'S'.
  SET PROPERTY OF CELL 'VALUE' = 'X'.

 
 CALL METHOD OF EXCEL 'SAVE'.
  FREE OBJECT EXCEL.

After that:


call function 'POPUP_TO_CONFIRM'
    EXPORTING
      TITLEBAR              = 'Display report'
      TEXT_QUESTION         = 'Display report?'
      DEFAULT_BUTTON        = '1'
      DISPLAY_CANCEL_BUTTON = 'X'
      START_COLUMN          = 25
      START_ROW             = 6
    IMPORTING
      answer                = ans.

if ans eq '1'.

    CALL METHOD cl_gui_frontend_services=>file_open_dialog
      EXPORTING
        window_title            = 'Select file for upload'
        default_extension       = 'Excel files (*.XLS)|*.XLS'
        file_filter             = 'Excel files (*.XLS)|*.XLS'
        initial_directory       = 'C:TEMP'
      CHANGING
        file_table              = li_filetable
        rc                      = lv_return
      EXCEPTIONS
        file_open_dialog_failed = 1
        cntl_error              = 2
        error_no_gui            = 3
        OTHERS                  = 4.

    read table li_filetable into lw_filetable index 1.
    p_file = lw_filetable-filename.


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 = p_file.

But after all, the excel process still works. In Task Manager it exists. How can I 'kill' it, directly after closing the window?

Thanks for any help.

Greetings

3 REPLIES 3

former_member181962
Active Contributor
0 Kudos

Hi,

You should probably free the excel object:

FREE OBJECT H_EXCEL.

raymond_giuseppi
Active Contributor
0 Kudos

Add

         CALL METHOD OF EXCEL 'QUIT'.

before freeing object.

Look at <a href="http://support.microsoft.com/kb/153043/fr">Controlling Alerts and Updating in MS Excel OLE Server</a> at microsft help.

         oWBook.SaveAs FileName:="C:my documentstest.xls"
         ' Closes the original workbook without saving changes.
         oWBook.Close False
         oXL.Quit    ' Closes the invisible instance of Microsoft Excel.

Regards

Former Member
0 Kudos

Hello

I can't CALL METHOD OF EXCEL 'QUIT' before freeing object, because in this case the Dialog window doesn't show up, and I can't save xls file under a new name. Any suggestions?