title: How do I reliably determine if a file is already opened in Microsoft Excel?
body: <p>I am implementing an interface to Excel. I am using COM to automate Excel directly from C++. Most of my application is working reliably.</p>
  
  <p>I however cannot detect if a file is already opened in Excel. If it is open, then I would like to inform the user to close it before running their simulation.</p>
  
  <p>I am not using MFC, VB, or .NET. My solution has to work for Excel versions 97 to 2010. If I can know the version of Excel programmatically, it is OK to use different techniques for different excel versions.</p>
  
  <p>I was looking for a file with the name "~$xxx" (where "xxx" is the original file name) in the same folder to determine if Excel has created a session lock. But this technique does not always work.</p>
  
  <p>A similar question is once the simulation is started in my program, I want to prevent the user from opening the file in Write mode (read-only mode is OK).</p>