Intermittent OLEObject Name property error
<p>This morning I've had problems with a section of my code which had previously worked fine.  Now i get (seemingly at random) one of 3 different error messages to do with the OLEObject i am referencing.  The most commonly occuring message is this:</p>

<blockquote>
  <p>Object library invalid or contains  references to onject definitions
  that could not be found</p>
</blockquote>

<p>edit:  when stepping into the code once the workbook has been reopened i get this message:</p>

<blockquote>
  <p>Run-time error '1004':
  Activate method of OLEObject Class failed</p>
</blockquote>

<p>Removing the .ActivateLine, I get:</p>

<blockquote>
  <p>Run-time error '1004':
  Unable to get the name property of the OLEObject class</p>
</blockquote>

<p>The debuger stops on the sub line, however it should be said that sometimes this code will run fine, to the point where sometimes it will throw an error for the name, I will end, restart and it will loop again, hit the same error and we repeat until all objects are deleted.  </p>

<p>I am currently trying to replicate the  two messages that occur during the code to add them to the post.  From memory they were something to do with the name property of OLECont- however this should not be a problem.</p>

<p>My code is below:</p>

<pre><code>Sub ClearGenerate()
Dim rngToClear As Range
Dim OLECont As OLEObject

'Clean down worksheet
Set rngToClear = Worksheets("Generate").Range("b17:F17")
rngToClear.Clear
Set rngToClear = Worksheets("Generate").Range("b24:F150")
rngToClear.Clear

'Clear out modules and buttons

For Each OLECont In Worksheets("Generate").OLEObjects
    OLECont.Activate
    ClearModule OLECont.Name
    OLECont.Delete
Next

End Sub
</code></pre>

<p>I added the OleCont.Activate in response to this post, but to no avail:</p>

<p><a href="https://stackoverflow.com/questions/24674893/i-found-an-excel-configuration-error-unable-to-get-the-object-property-of-the-o">I found an Excel configuration error: Unable to get the Object property of the OLEObject class</a></p>