select sheets excel

delphi, delphi-xe3

Solution

This works well for me in XE3:

var
  XLApp: OleVariant;
  Sheet: OleVariant;
begin
  XLApp := CreateOleObject('Excel.Application');
  XLApp.Visible := True;
  XLApp.Workbooks.Open('C:\Test\Testing.xls');
  ShowMessage(XLApp.Workbooks[1].Worksheets[1].Name);  // Sheet1
  Sheet := XLApp.Worksheets.Item['Sheet3']; 
  ShowMessage(Sheet.Name);                             // Sheet3
  Sheet.Select;
  // This also works
  XLApp.WorkSheets.Item['Sheet1'].Select;              // Sheet1
end;

Problem

XE3 use delphi with excel ole automation. With this code I open and read / write in the cells, but I can not select different sheets (Sheet1, Sheet3 etc.) ``` begin L_vi.Caption: = 'D: \ bd1 \ file_supporto \ Vi.xls'; Ex: = createoleobject ('Excel.Application'); Ex.visible: = true; Ex.workbooks.open (L_vi.Caption); Ex.cells [1,1]: = 'test'; Sheets: = Ex.Workbooks [1]. Worksheets ['Sheet3']; ``` Can you help? thanks P.S. i resolved so: ``` Ex.Workbooks [1]. Worksheets ['Sheet3'].select; ``` thanks.

Original source