I'm not really an expert on this, but this is my understanding of it:
Rory - memory is allocated for variables when the code is compiled - correct?
VBA isn't strictly a compiled language, but yes the compiler knows from the declarations how much memory to allocate when the code is loaded.
But if you have late binding, I guess the initial variable (as object) is allocated at the beginning, but once Excel figures out exactly what the object's variable type is (ie. Document), which is done at run time (right?), does that change the memory allocated??
All object variables are just pointers, so the actual memory allocation for the variable itself is the same regardless. (strictly speaking, it's a pointer to a particular
interface rather than an actual object per se, since an object can implement more than one interface. In fact almost all COM objects implement interfaces inherited from IDispatch and IUnknown so that they can be both late and early bound.)
If you early bind, the compiler can preload the various vTables of exposed properties/methods etc. which presumably has some memory overhead.
If you late bind, the compiler can't do that, which is why it's slower. (It has to call the IDispatch interface's GetIDsOfNames function to get the dispid (memory location) of a function name, and then the Invoke method to actually call the function.)
The upshot is that I'm not sure there's much, if any, difference in terms of memory allocation, since a pointer is a pointer, regardless of what it points to, and the actual object in question will occupy the same amount of memory when it's created. The only real difference at run-time is the speed of execution.