Error Closing OLEObject Excel.Sheet After Creation
<p>Say you wish to create and then close a linked excel sheet:</p>
<pre><code>Dim shp As shape
Set shp = Application.ActiveDocument.Shapes.AddOLEObject(ClassType:=&quot;Excel.Sheet&quot;)

DoEvents

shp.OLEFormat.Object.Close
</code></pre>
<p>This fails with this error:</p>
<blockquote>
<p>Run time error '1004'</p>
<p>Close method of Workbook class failed</p>
</blockquote>
<p>Why? I can't seem to find any examples of this occurring in word, the closest example I can find is <a href="https://stackoverflow.com/questions/10612502/error-when-closing-an-opened-workbook-in-vba-userform">this</a>, which is more related with the user form than the actual function.</p>
<p>The error seems very generic, is there any way to get a more specific reason &quot;why&quot; the close method is failing? It seems if you google around, you'll find this error is thrown for all sorts of reasons(<a href="http://www.mrexcel.com/forum/excel-questions/726116-run-time-error-1004-method-close-object-_workbook-failed.html" rel="nofollow noreferrer">example</a>, <a href="http://www.mrexcel.com/forum/excel-questions/726116-run-time-error-1004-method-close-object-_workbook-failed.html" rel="nofollow noreferrer">another example</a>) but non of these seem to have anything to add to this particular issue.</p>
<p>Note: A similar error occurs with &quot;shp.OLEFormat.Object.Save&quot;</p>