This one has be puzzled. I've current experienced this in Access 2010 and a new clean install on a new PC of Access 2013. The syntax , I have used for years without issue.
Without all the other bits I start with
Dim xl As Object
A little later I have
Set xl = CreateObject("Excel.Application")
I have a command button that fires the sub with this in. If I use it, I get the error message in the title. If I put a break point on the second line shown and run the code., when it breaks at the second line, I can press F8 to step the code and it works! Let the rest of the code run - all good - lots of Excel object based code that all works.
Remove the break point and try again - and the same - it gets to the CreateObject line - thinks about it for about 30 seconds and returns the error.
I'm out of ideas! Any one else got a bright idea. I do not want to have to reference Excel as the will be being deployed onto many PCs of varying versions, and keeping it object based stops the problem of being backward compatible.