private void btnRunExcel_Click(object sender, EventArgs e) { try { myClass myclass = new myClass(); List<FPExcelOutPut> LayOutExcel = new List<FPExcelOutPut>(); foreach (string DbName in this.listBoxDBF.Items) { myclass.runFPExcel(DbName, toolStripProgressBar1, toolStripLabel1,ref LayOutExcel); } APP_Code.ExportToExcel exportToExcel = new APP_Code.ExportToExcel(); //string tmp = Path.GetDirectoryName(txtDatName.Text); string tmpFileExcelName = "Prueba"; if (File.Exists(_excelPahtOut + "\\FP" + tmpFileExcelName + ".xlsx")) File.Delete(_excelPahtOut + "\\FP" + tmpFileExcelName + ".xlsx"); FileInfo excelTargetFile = new FileInfo(_excelPahtOut + "\\FP" + tmpFileExcelName + ".xlsx"); exportToExcel.MyExportToExcel(LayOutExcel, excelTargetFile); exportToExcel = null; MessageBox.Show("Done"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }