Below code works fine (By Interop.Excel 12.0)
static private void Merge(string sourceFile,string targetFile)
{
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
Microsoft.Office.Interop.Excel.Workbook workbook1 = excel.Workbooks.Open(sourceFile,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
Microsoft.Office.Interop.Excel.Workbook workbook2 = excel.Workbooks.Open(targetFile,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing);
Microsoft.Office.Interop.Excel.Worksheet worksheet1 = (Microsoft.Office.Interop.Excel.Worksheet)workbook1.Sheets["TestCopyVBA1"];
Microsoft.Office.Interop.Excel.Worksheet worksheet2 = (Microsoft.Office.Interop.Excel.Worksheet)workbook2.Sheets["TestcopyVBA2"];
worksheet2.Copy(Missing.Value, worksheet1);
workbook1.Save();
workbook1.Close(false, Type.Missing, Type.Missing);
workbook2.Close(false, Type.Missing, Type.Missing);
}
While using Aspose.Cell 7.0 , the VBA in TestCopyVBA2 is missing. Test excel files attached.
string filepath = @"TestCopyVBA1.xls";
string filepath1 = @"TestCopyVBA2.xls";
string filepathoutput = @"Merged1.xls";
Workbook wb = new Workbook();
Workbook wb2 = new Workbook(filepath1);
Workbook wb1 = new Workbook(filepath);
wb.Worksheets.Clear();
wb.Copy(wb1);
wb.Worksheets.Insert(1, SheetType.Worksheet);
wb.Worksheets[1].Copy(wb2.Worksheets[0]);
wb.Save(filepathoutput);
Thank you so much