I am having an issue that I am sure is silly and I am missing the obvious. I get the following error when I put "wksht.Cells[1,1].Select;" into the code to select the upper most left hand cell.
Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement.
here is the Method its being called in:
public void ValueSaves(Excel.Workbook wb, Excel.Application excelApp)
{
Excel.Worksheet wksht;
excelApp.ScreenUpdating = false;
for (int i = 0; i < lstSaveSheet.Items.Count; i++)
{
string range = lstSaveRange.Items[i].ToString();
wksht = wb.Sheets[lstSaveSheet.Items[i].ToString()];
Boolean sheetProtected = false;
if (wksht.ProtectContents)
{ sheetProtected = true; }
wksht.Unprotect();
if (range == "whole sheet")
{
//select & copy whole sheet
wksht.get_Range("a1").EntireRow.EntireColumn.Copy(Type.Missing);
//paste whole sheet as a value
wksht.get_Range("a1").EntireRow.EntireColumn.PasteSpecial(Excel.XlPasteType.xlPasteValues, Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false);
}
else
{
string[] CellRefs = lstSaveRange.Items[i].ToString().Split(':');
wksht.get_Range(CellRefs.First(), CellRefs.Last()).Copy(Type.Missing);
//paste range as a value
wksht.get_Range(CellRefs.First(), CellRefs.Last()).PasteSpecial(Excel.XlPasteType.xlPasteValues, Excel.XlPasteSpecialOperation.xlPasteSpecialOperationNone, false, false);
}
wksht.Cells[1, 1].Select; <== Error here
if (sheetProtected)
{ wksht.Protect(); }
Clipboard.Clear();
excelApp.ScreenUpdating = true;
}
}