At its simplest, CreateObject
creates an instance of an object whereas GetObject
gets an existing instance of an object. Determining whether an object can be created or gotten will depend on it's Instancing property. Some objects are SingleUse (eg, WMI) and cannot be created if they already exist. Other objects (eg, Excel) are MultiUse and allow multiple instances to run at once. If an instance of an object does not already exist and you attempt GetObject
, you will receive the following trappable message: Run-time error '429': ActiveX component can't create object
.
GetObject requires at least one of these two optional parameters to be present:
CreateObject has one required parameter and one optional parameter:
Class is always comprised of two parts in the form of Application.ObjectType
:
Some example classes are: