By Adam Nagy
This blog post's Command Execution Behavior section already talks about this but might be worth mentioning it again and providing some more details.
There are three ways to run an existing command: Execute, Execute2(Synchronous=False) and Execute2(Synchronous=True).
If we ran the same command that was also used in the other article in three different ways then we would observe the following behaviour:
Sub TestControlDefinitionExecute() Dim cm As CommandManager Set cm = ThisApplication.CommandManager Dim cds As ControlDefinitions Set cds = cm.ControlDefinitions Dim cd As ControlDefinition Set cd = cds("AssemblyPlaceComponentCmd") Debug.Print "Before Execute" Call cd.Execute 'Call cd.Execute2(False) 'Call cd.Execute2(True) Debug.Print "After Execute" End Sub
So Execute2(Synchronous=False) is fully asynchronous, it does not wait for dialogs either, whereas Execute() does, and only returns once the dialog got dismissed. Execute2(Synchronous=True) is fully synchronous as it waits for the command to finish completely.
In case of commands (e.g. AppFileOpenCmd) which show a dialog but have no interactive bits like moving a component around in the document view, the Execute() and Execute2(True) functions return at the same time, right after the dialog got dismissed.