A lot of errors you've been made...
Please, read my comments:
Why to use methods of
class, if you can initiate variables directly?
A drive letter has been missed!
//string folder = Path.GetDirectoryName(@"\\OpsVsAdp\\Files\\Daily\\TempHours.xlsx");
//string fileName = Path.GetFileNameWithoutExtension(@"\\OpsVsAdp\\Files\\Daily\\TempHours.xlsx");
//string extension = Path.GetExtension(@"\\OpsVsAdp\\Files\\Daily\\TempHours.xlsx");
Rather than above, use this:
string fullFileName = @"C:\OpsVsAdp\Files\Daily\TempHours.xlsx";
Below part of code won't be necessary, because you can open file in Excel and "move" it into different location by using
FileInfo info = new FileInfo(fileName + extension);
string newName = folder + "\\" + fileName + "_" + ISO_Date() + extension;
You should use
variable instead of string containing a path to file. Doing it this way is called "good programming practice" and let you avoid of several mistakes later.
MyApp = new Excel.Application();
MyApp.Visible = false;
xlBook = MyApp.Workbooks.Open(fullFileName);
To be able to modify sheet name, you should check its name firstly.
xlSheet = (Excel.Worksheet)xlBook.Worksheets.get_Item(1); // Explicit cast is not required here
// Check and change sheet name to 'Sheet1'
if(xlSheet.Name != "Sheet1")
xlSheet.Name = "Sheet1";
//you don't need to save a workbook now
//as i mentioned above, you can do it later by using SaveAs method
variables have been initiated, but never used!
If you know the exact address of cell containing date (or date range or any other data), you can change its content directly!
//int totalRows = xlSheet.Rows.Count;
//int totalCols = xlSheet.Columns.Count;
// in second row
// replace word 'yesterday' with date
// in case of date range, remove the first date
string stmp = (string)xlSheet.Cells[2, 1].Value;
if(stmp == "yesterday")
xlSheet.Cells[2, 1].Value = DateTime.Today.AddDays(-1);
xlSheet.Cells[2, 1].Value = stmp.Remove(ind, ind);
Sorry, but the other part of code is not clear to me...
To save workbook in different location, call this:
string sNewFileName = Path.Combine(Path.GetDirectoryName(fullFileName),
string.Concat(Path.GetFileNameWithoutExtension(fullFileName), "_", DateTime.Today.ToString("yyyyMMdd"), ".xslx"));
do not forget release resources! For further details, please see: How to Release COM Interop Objects so the Called Program Can Exit