I’m encountering an issue when creating an Excel OLE object from Delphi.
Initially, everything functions correctly: I can change sheets and read/write cell values.
However, when I set the parent of the Excel window to a Delphi form, I experience unexpected behavior.
File options like saving and printing become disabled, and the main title bar changes from the “file name – Excel” to just “Excel.”
Also switching sheets, settings cell values cause errors.
The only way to restore normal functionality is by double-clicking a cell on the sheet.
Is there any way to refresh it from code not by double click?
ExcelApp := CreateOleObject('Excel.Application');
ExcelApp.Visible := False;
workbook := ExcelApp.Workbooks.Open(FileName);
Worksheet := Workbook.WorkSheets[1];
Worksheet.Select;//works
Windows.SetParent(fExcelHandle, Panel1.Handle);
ShowWindow(fExcelHandle, SW_SHOW);
Worksheet := Workbook.WorkSheets[1];
Worksheet.Select; //return error
Worksheet := Workbook.WorkSheets[1]; //double cell click
Worksheet.Select; //works
Radosław Jerzak is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.