Yes that is a similar way and can work just always opens and closes the excel app instance
Let think to not close that instance and just circulate the workbooks/files in one instance.
In my new I ommited
m_oExcelKP01 := win_oleCreateObject("Excel.Application")
m_workbook := m_oExcelKP01:Workbooks:Open( KP01 )
m_sheet := m_oExcelKP01:Sheets("m_sheet1")
m_workbook:saved := .t.
m_workbook:close()
m_workbook := Nil
m_sheet := Nil
Release m_oExcelKP01
m_oExcelKP02 := win_oleCreateObject("Excel.Application")
m_workbook := m_oExcelKP02:Workbooks:Open( KP02 )
m_sheet := m_oExcelKP02:Sheets("m_sheet1")
m_workbook:saved := .t.
m_workbook:close()
m_workbook := Nil
m_sheet := Nil
Release m_oExcelKP02
and keept just only one variable m_oExcel, not m_oExcelKP01 and m_oExcelKP02 (in your example)
the
m_workbook := Nil
m_sheet := Nil
Release m_oExcelKP01
is ok if you want to completely close the excel instance from windows
but if you keep it, without closing m_oExcel := win_oleCreateObject("Excel.Application") , and with only
m_workbook := m_oExcel:Workbooks:Open( KP01 )
m_sheet := m_oExcel:Sheets("m_sheet1")
you close only the workbook and then, with alternatively open/close, open/close ... the next workbooks, you keep all the way, in the memory, the same excel instance and you havent to open it again.
Just a manipulation with workbooks and not excel instances.
example:
we have KP01.xls, KP01.xls ...
m_oExcelKP01 := win_oleCreateObject("Excel.Application") - opens the excel app instance in the windows memory
m_workbook := m_oExcel:Workbooks:Open( KP01 ) - load the excel workbook/file in the instance
m_sheet := m_oExcel:Sheets("m_sheet1") - focus to first sheet (in my example I renamed the default name from sheet1 to m_sheet1
.... other code that manipulate the sheet data
m_workbook:saved := .t. - send the saved signal to the excel instance regarding the workbook status
m_workbook:close() - close the active excel workbook/file
now just
m_workbook := m_oExcel:Workbooks:Open( KP02 ) - load the next excel workbook/file in the existing excel instance without close the excel app in windows
...
and so on