Note: If a file with the new name already exists, it overwrites it. If VarIsNull(ExcelWorksheet) = False thenĮxcelWorksheet.Cells := 'We just created a new Excel file with one worksheet!' //, in this case, text is added to Cell A1Į //selects Cell A2 connect to Excel Worksheet using either the ExcelApplication or ExcelWorkbook handleĮxcelWorksheet := ExcelWorkbook.WorkSheets // specifies the first worksheet May be helpful to set to True during testing and debugging.ĮxcelWorkbook := (- 4167) If VarIsNull(ExcelApplication) = False thenĮxcelApplication.Visible := True //set to False if you do not want to see the activity in the backgroundĮxcelApplication.DisplayAlerts := False //ensures message dialogs do not interrupt the flow of your automation process. add error/exception handling code as desired be sure ComObj and Variants units are included in the "uses" clauseĮxcelFileName := 'C:\PhysiologyWeb\delphi_code_examples\new_excel_file.xlsx' //replace file name with the name of your fileĮxcelApplication := CreateOleObject( 'Excel.Application') Procedure TForm1.OpenANewExcelFileAndSave(Sender: TObject) ĮxcelApplication, ExcelWorkbook, ExcelWorksheet: Variant
0 Comments
Leave a Reply. |