I need to merge the worksheets of some workbooks into one new workbook. What I tried is this, but I am getting "Unable to get the Copy property of the Worksheet class". What am I doing wrong? Thank you!
foreach (var sourceFileName in sourceFileNames)
{
var sourceWorkbook = GetWorkbook(sourceFileName);
var sourceSheet = (Worksheet)sourceWorkbook.Worksheets[1];
var lastSheetInDestinationWorkbook = (Worksheet)_destinationWorkbook.Worksheets[_destinationWorkbook.Worksheets.Count];
sourceSheet.Copy(After: lastSheetInDestinationWorkbook);
sourceWorkbook.Close();
}
((Worksheet)_workbook.Sheets[1]).Delete();
_workbook.Save();