title: How to access OLE Objects from MS Excel using Microsoft.Interop Excel
body: <p>I am trying to access a report which is a OLE Object(embedded into an Excel worksheet).</p>
  
  <p>I am trying to do this from a C# console application using the Microsoft.Interop.Excel API.</p>
  
  <p>I am successfully able to iterate through the OLE Objects present in a worksheet. <strong>However, when i try to access the <em>Object</em> property of the OLEObject instance, i am getting a COM exception.</strong></p>
  
  <p>Has anyone tried doing this before successfully. Please assist me with sample code.</p>
  
  <p>Code i tried for POC as follows</p>
  
  <pre><code>static void Main(string[] args)
      {
          string fileName = string.Empty // some excel file path
          Application _excelApp = new Application();
          _excelApp.AutomationSecurity = MsoAutomationSecurity.msoAutomationSecurityForceDisable;
  
          Workbook workBook = _excelApp.Workbooks.Open(fileName,
       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);
  
          for (int i = 1; i &lt;= workBook.Sheets.Count; i++)
          {
              var sheet = workBook.Sheets[i] as Worksheet;
  
              try
              { 
                  OLEObject obj = sheet.OLEObjects("BReport") as OLEObject;
                  Console.WriteLine(obj.Name);
                  Console.WriteLine(obj.Object.ToString());                    
              }
              catch
              {                  
                  continue;
              }
          }
  </code></pre>
  
  <p>Thanks in Advance..</p>