In VBA, you can call your methods/functions with Call ahead of them, to tell the compiler explicitly that you don't want to use the return value if there is any.
Now the DoEvents function should also be possible to be called via Call, but I can't make it happen.
When I type:
Call DoEvents
it simply says "syntax error" when compiling.
Why can't I use Call infront of DoEvents?
Using VBA from the VBE in Excel 2016, IIRC it also didn't work in 2013, 2010, etc.
tldr; You can
Callit, but only explicitly from the VBA module.As the documentation linked by @Gary'sStudent (see the application agnostic version here) points out,
DoEventsis actually aFunctionnot aSub, and it will always return 0 in VBA. In unhosted Visual Basic (i.e. VB6) it returns the total number of open windows. My completely unsubstantiated guess as to why it returns zero is that in VBA the top level window of the process that the code is running isn't owned by the code you're executing.The function itself is in the
VBA.Interactionmodule, as you can see in the Object Browser:That said, you should note that you can use the
DoEventsfunction preceded by theCallkeyword - but you need to explicitly reference theVBAassembly:Again, this is just speculation, but I suspect the reason has to do with the internal implementation. Typically that would be calling the SwitchToThread function (which the vbe7.dll does import). But the nature of the return value points to enumerating the windows that are yielded to, so it probably just needs a handle to
VBAto run. There isn't anything in the typelib that suggests it's different from any of the other functions in the Interaction module (although there may be a flag that I missed somewhere):The nature of the compile error "Expected: identifier" indicates that there is something internal that is "hiding"
DoEventsfrom the globally accessible VBA functions.Final note: The
Call Foosyntax is completely superfluous - all it does is explicitly discard the return value of a function. Not assigning the return value does exactly the same thing.