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 Excel quit without save

Former Member
0 Likes
5,051

Hi all.

I'm reading an Excel file with OLE.

I'm trying to close it without the annoying message to save changes (modified copy of ALSM_EXCEL_TO_INTERNAL_TABLE).

The WORKBOOK class has a CLOSE method with a parameter called SAVECHANGES.

This parameter is of type BOOLEAN.

general code i've used:

call method of workbook 'CLOSE' EXPORTING #1 = space. CALL METHOD OF application 'QUIT'. FREE OBJECT h_cell. m_message. FREE OBJECT h_cell1. m_message. FREE OBJECT range. m_message. FREE OBJECT worksheet. m_message. FREE OBJECT workbook. m_message. FREE OBJECT application. m_message.

I've tried 0, -1, and other values instead of SPACE, but i keep getting an OLE error.

Does someone know how to call this method with the VBA-equivalent of a BOOLEAN parameter? ABAP type BOOLEAN is CHAR1, which is not the same.

Thanks.

Jester

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
3,145

Hi Jes,

use DOI method

close_document
You use this method to close a document in the office application
CALL METHOD document->close_document
EXPORTING do_save = do_save
no_flush = no_flush
IMPORTING has_changed = has_changed
error = error
retcode = retcode.
Description of parameters
Parameter Optional Description
do_save X Determines whether the document should be saved
has_changed X Flags whether the office application document was changed
When you have executed the method close_document without saving the document,
you must always execute the method release_document to initialize the document.
You can also call the close_document method even if the document is already
closed. This does not return an error, and in this way you can retrieve a correct value
for the has_changed parameter. This is safer and quicker than calling is_open
followed by close_document.

Please refer to full documentation of [desktop office integration|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCFESDE6/BCFESDE6.pdf]

Kind regards,

Clemens

Hi all.

I'm reading an Excel file with OLE.

I'm trying to close it without the annoying message to save changes (modified copy of ALSM_EXCEL_TO_INTERNAL_TABLE).

The WORKBOOK class has a CLOSE method with a parameter called SAVECHANGES.

This parameter is of type BOOLEAN.

general code i've used:

call method of workbook 'CLOSE' EXPORTING #1 = space. CALL METHOD OF application 'QUIT'. FREE OBJECT h_cell. m_message. FREE OBJECT h_cell1. m_message. FREE OBJECT range. m_message. FREE OBJECT worksheet. m_message. FREE OBJECT workbook. m_message. FREE OBJECT application. m_message.

I've tried 0, -1, and other values instead of SPACE, but i keep getting an OLE error.

Does someone know how to call this method with the VBA-equivalent of a BOOLEAN parameter? ABAP type BOOLEAN is CHAR1, which is not the same.

Thanks.

Jester

14 REPLIES 14
Read only

Former Member
0 Likes
3,145

This message was moderated.

Read only

Former Member
0 Likes
3,145

Hi Jes,

Please try this

data: h_excel type ole2_object, 
         h_mapl type ole2_object. 

  get property of h_excel 'ActiveSheet' = worksheet.
  get property of h_excel 'ActiveWorkbook' = h_mapl.

  call method of h_mapl 'SAVEAS'
    exporting
    #1 = p_file  " Default File name ("C:\test.xls")
    #2 = 1.

  call method of h_mapl 'CLOSE'.
  call method of h_excel 'QUIT'.

Thanks & Regards

Rahul

Read only

0 Likes
3,145

Thanks Rahul, but i don't want to save my file. I want to close it without save.

Read only

Clemenss
Active Contributor
0 Likes
3,146

Hi Jes,

use DOI method

close_document
You use this method to close a document in the office application
CALL METHOD document->close_document
EXPORTING do_save = do_save
no_flush = no_flush
IMPORTING has_changed = has_changed
error = error
retcode = retcode.
Description of parameters
Parameter Optional Description
do_save X Determines whether the document should be saved
has_changed X Flags whether the office application document was changed
When you have executed the method close_document without saving the document,
you must always execute the method release_document to initialize the document.
You can also call the close_document method even if the document is already
closed. This does not return an error, and in this way you can retrieve a correct value
for the has_changed parameter. This is safer and quicker than calling is_open
followed by close_document.

Please refer to full documentation of [desktop office integration|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCFESDE6/BCFESDE6.pdf]

Kind regards,

Clemens

Read only

Former Member
0 Likes
3,145

Hi Clemens.

This sounds interesting, but i don't understand. instance DOCUMENT is based on what class?

I didn't find anything in the linked document, and this is old OLE documentation.

Please provide more info if possible.

Thanks.

Jes

Read only

Clemenss
Active Contributor
0 Likes
3,145

Hi Jes,

the faster and more stable way of OLE goes via desktop office intergration, that's my document link for. There are blogs, too (i.e. Rainer Ehre).

I used it for Excel integration and used

a proxy MO_DOCUMENT_PROXY Type Ref To I_OI_DOCUMENT_PROXY

excel interface MO_SPREADSHEET Type Ref To I_OI_SPREADSHEET

error object MO_ERROR Type Ref To I_OI_SPREADSHEET

and for the container where I opened the excel

MO_CONTAINER_CONTROL Type Ref To I_OI_CONTAINER_CONTROL

Here an Excerpt for opening an existing Excel

METHOD open_document.
...
  mo_document_proxy->open_document(
    EXPORTING
      document_title   = lv_doc_title
      document_url     = lv_doc_url
      open_inplace     = abap_true
    IMPORTING
      error            = mo_error
         ).
      IF mo_error->error_code NE c_oi_errors=>ret_ok.
        lv_error = abap_true.
      ENDIF.
  IF mo_spreadsheet IS INITIAL.
    CALL METHOD mo_document_proxy->get_spreadsheet_interface
      IMPORTING
        sheet_interface = mo_spreadsheet
        error           = mo_error
        .

    IF  mo_error->has_failed IS NOT INITIAL.
...
      RAISE EXCEPTION TYPE ...
    ENDIF.
  ENDIF.

ENDMETHOD.

and later

mo_document_proxy->close_document( do_save = abap_true ).
    mo_document_proxy->release_document( ).

Regards,

Clemens

Read only

Former Member
0 Likes
3,145

Hi Clemens.

Thanks for the info.

I'll be sure to take a closer look at these tools.

my context is a modified copy of ALSM_EXCEL_TO_INTERNAL_TABLE, so I'd prefer not having to re-invent the whole process.

Thanks again.

Regards,

Jes

Read only

Clemenss
Active Contributor
0 Likes
3,145

Hi Jes,

.... and it's worth the try: You can access all existing sheets, any cell and have a whole bunch of methods for everything.

Oops, I think I posted a wrong link, please try here

[ Desktop Office Integration (BC-CI)|http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCCIOFFI/BCCIOFFI.pdf]

Best regards,

Clemens

Read only

kheth
Active Participant
0 Likes
3,145

Hi Jes,

in reply to your very first question:

The equivalents of the boolean values true and false are 1 and 0 (as numbers, not as text). The code

CALL METHOD OF workbook 'CLOSE'
  EXPORTING
    #1 = 0.

works fine and closes the workbook without any further message.

Regards,

Karsten

Read only

Former Member
0 Likes
3,145

Hi Karsten.

Weird, when i try this, i get an OLE error.

It's no longer an issue, though. I'm going to close the topic. The popup is not critical.

Thanks.

Jes

Read only

Former Member
0 Likes
3,145

Jesse, I'm facing the same error as yourself.

Would appreciate if you can share the resolution for this one - were you able to close the workbook without saving ?

thanks

CK

Read only

Former Member
0 Likes
3,145

Hello. I just had the same problem. The solution for me was more simple than you would think. Instead of just declaring the first parameter "SaveChanges", you need to declare also the two other paramters of the Close method.


GET PROPERTY OF application 'ActiveWorkbook' = workbook.

  CALL METHOD  OF workbook 'CLOSE'

    EXPORTING

      #1 = 0

      #2 = 0

      #3 = 0.

Read only

0 Likes
3,145

Hi!

For me worked both ways. With only one parameter and with 3 parameters.

Read only

Former Member
0 Likes
3,145
get property of application 'ActiveWorkbook' = workbook.
   call method of workbook 'CLOSE'
     exporting
       #1 = 0
       #2 = 0
       #3 = 0.

Hi, Strandfelt

I have modified ALSM_EXCEL_TO_INTERNAL_TABLE with the coding. Now i get a OLE Error with the close method. I've tried one or 3 export parameters.

We are using Office 2010. Could anyone tell me what the probleme could be?

Best regards

Markus