![]() You can pass an object returned by the CreateObject function to a function expecting an object as an argument. The reference through an early-bound variable can give better performance, but can only contain a reference to the class specified in the declaration. Set xlApp = CreateObject("Excel.Application") For example, you can declare and create the following Microsoft Excel references: Dim xlApp As Excel.Application To create an object variable that results in early binding, that is, binding when the program is compiled, declare the object variable with a specific class ID. However, access to the object through that variable is late bound that is, the binding occurs when your program is run. ' Close Excel with the Quit method on the Application object.ĭeclaring an object variable with the As Object clause creates a variable that can contain a reference to any type of object. ' Save the sheet to C:\test.xls directory. ' Place some text in the first cell of the sheet.Į(1, 1).Value = "This is column A, row 1" ' Make Excel visible through the Application object. In the following example, you access properties and methods of the new object by using the object variable, ExcelSheet, and other Microsoft Excel objects, including the Application object and the Cells collection. After an object is created, you reference it in code by using the object variable you defined. This code starts the application creating the object, in this case, a Microsoft Excel spreadsheet. Set ExcelSheet = CreateObject("Excel.Sheet") ' Declare an object variable to hold the object To create an ActiveX object, assign the object returned by CreateObject to an object variable. For example, a word processing application may provide an Application object, a Document object, and a Toolbar object. The type or class of object to create.Įvery application that supports Automation provides at least one type of object. The name of the application providing the object. The class argument uses the syntax appname. If servername is an empty string (""), the local machine is used. The name of the network server where the object will be created. ![]() The application name and class of the object to create. The CreateObject function syntax has these parts: Part
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |