2009 Oct 30 7:02 PM
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
2009 Oct 31 2:02 PM
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
2009 Oct 31 5:21 AM
2009 Oct 31 6:12 AM
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
2009 Nov 02 12:50 PM
Thanks Rahul, but i don't want to save my file. I want to close it without save.
2009 Oct 31 2:02 PM
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
2009 Nov 02 12:52 PM
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
2009 Nov 02 3:20 PM
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
2009 Nov 02 3:26 PM
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
2009 Nov 02 6:47 PM
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
2010 Jan 13 3:28 PM
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
2010 Jan 13 3:51 PM
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
2014 Jun 18 10:29 PM
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
2014 Jul 29 12:21 PM
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.
2014 Sep 19 10:10 AM
Hi!
For me worked both ways. With only one parameter and with 3 parameters.
2014 Nov 18 3:24 PM
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
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |