Name
CreateObject Function
Syntax
CreateObject(servername.Typename [, Location])
-
servername Use: Required
Data subtype: String
The name of application providing the object.
-
Typename Use: Required
Data subtype: String
The type or class of the object to create.
-
Location Use: Optional
Data subtype: String
The name of the server where the object is to be created.
Return Value
A reference to an ActiveX object.
Description
Creates an instance of an OLE Automation (ActiveX) object. Prior to calling the methods, functions, or properties of an object, you are required to create an instance of that object. Once an object is created, you reference it in code using the object variable you defined.
Rules at a Glance
In order to assign the object reference to a variable, you must use the
Setkeyword. For example:Dim oDoc Set oDoc = CreateObject("Word.Document")servernameandtypenameare not arbitrary values. Instead, the combination ofservername.typenameis known as a programmatic identifier or ProgID and is defined in the system registry. ProgIDs are included among the subkeys ofHKEY_CLASSES_ROOT. Some common programmatic identifiers are shown in the following table:ProgID
Description
ADODB.ConnectionAn ActiveX Data Objects connection
ADODB.RecordsetAn ActiveX Data Objects recordset
DAO.DBEngineData Access Objects
Excel.ApplicationMicrosoft Excel
Excel.ChartA Microsoft Excel chart
Excel.SheetA Microsoft Excel workbook
MAPI.SessionCollaborative Data Objects
Outlook.Application ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access