title: Open an excel file in exclusive mode using interop in C#
body: <p>In my application I want to be able to open an excel file that already exists, and add information to this file. I use the Microsoft Interop libraries. I have noticed that if you create a new spreadsheet using Add and then Saveas you can set the file to be in exclusive mode until you close the excel application. </p>
  
  <p>However I haven't found a way to do the same when Opening an existing file. The reason I want to do that is because, if I open the excel file while my application is open, then I get an exception. I presume that when I am opening the excel file using excel, it is automatically opened in exclusive mode.</p>
  
  <p>I though of opening the file and then using saveas, but it didn't work.</p>
  
  <pre><code>private object missing=Type.Missing;
  workbook = workbooks.Open(excelfilename,missing, false, missing, missing, missing,missing,missing,missing,missing,false, missing,missing, missing, missing);
  workbook.SaveAs((String)excelfilename, missing, missing, missing, missing, missing, Excel.XlSaveAsAccessMode.xlExclusive, Excel.XlSaveConflictResolution.xlLocalSessionChanges, missing, missing, missing, missing); 
  </code></pre>
  
  <p>I am getting the exception later in the code:</p>
  
  <pre><code>Excel.Range testrange = sheet.get_Range(rangetext);
  </code></pre>
  
  <p>The exception I am getting is a COMException, "Exception from HRESULT: 0x800401A8".</p>