The follow line of code...
wbkSource.Sheets(strFromSht).Copy(wbk.Sheets(1));
getting error
Error 2 Non-invocable member 'Microsoft.Office.Interop.Excel._Workbook.Sheets' cannot be used like a method.
Can someone please help me. My intent is to copy a worksheet to another
workbook
private String strWorkBookLocation = "C:\\PivotFiles\\source.xls";
private String strWbkLocation = "C:\\PivotFiles\\temp.xls";
private String cstrPivotTableSheet = "Pivot Table";
private String strFromSht = "Source";
Excel.Application app;
Excel.Workbook wbk;
Excel.Worksheet sht;
Excel.Worksheet sh;
Excel.Workbook wbkSource;
DataSet dSet = new DataSet();
DataGrid dg = new DataGrid();
int y = 2;
int x = 0;
try
{
FetchMFRData(ref dSet, "12/24/2010", "12/24/2010");
dg.DataSource = dSet;
dg.DataBind();
FileStream fs = new FileStream(strWorkBookLocation, FileMode.Create);
StreamWriter tw = new StreamWriter(fs);
HtmlTextWriter writer = new HtmlTextWriter(tw);
dg.RenderControl(writer);
writer.Flush();
writer.Close();
tw.Close();
fs.Close();
app = new Excel.Application();
app.DisplayAlerts = false;
wbkSource = app.Workbooks.Open(strWorkBookLocation,
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);
wbk = app.Workbooks.Open(strWbkLocation,
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);
foreach (Excel.Worksheet sheet in wbk.Sheets)
{
if (sheet.Name.Equals(cstrPivotTableSheet) == false)
sheet.Delete();
}
wbkSource.Sheets(strFromSht).Copy(wbk.Sheets(1));
}
catch (Exception ex)
{
}
}
}