Skip to main content This browser is no longer supported. Show
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. Understanding objects, methods, properties, and events
In this articleObjects and collectionsAn object represents an element of an application, such as a worksheet, a cell, a chart, a form, or a report. In Visual Basic code, you must identify an object before you can apply one of the object's methods or change the value of one of its properties. A collection is an object that contains several other objects, usually, but not always, of the same type. In Microsoft Excel, for example, the Workbooks object contains all the open Workbook objects. In Visual Basic, the Forms collection contains all the Form objects in an application. Items in a collection can be identified by number or by name. For example, the following procedure identifies the first open Workbook object.
The following procedure uses a name specified as a string to identify a Form object.
You can also manipulate an entire collection of objects if the objects share common methods. For example, the following procedure closes all open forms.
Returning objectsEvery application has a way to return the objects it contains. However, they are not all the same, so you must refer to the Help topic for the object or collection that you are using in the application to see how to return the object. MethodsA method is an action that an object can perform. For example, Add is a method of the ComboBox object, because it adds a new entry to a combo box. The following procedure uses the Add method to add a new item to a ComboBox.
PropertiesA property is an attribute of an object that defines one of the object's characteristics, such as size, color, or screen location, or an aspect of its behavior, such as whether it is enabled or visible. To change the characteristics of an object, you change the values of its properties. To set the value of a property, follow the reference to an object with a period, the property name, an equal sign (=), and the new property value. For example, the following procedure changes the caption of a Visual Basic form by setting the Caption property.
You can't set some properties. The Help topic for each property indicates whether you can set that property (read-write), only read the property (read-only), or only write the property (write-only). You can retrieve information about an object by returning the value of one of its properties. The following procedure uses a message box to display the title that appears at the top of the currently active form.
EventsAn event is an action recognized by an object, such as clicking the mouse or pressing a key, and for which you can write code to respond. Events can occur as a result of a user action or program code, or they can be triggered by the system. See also
Support and feedbackHave questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback. What is object-oriented programming?Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior. OOP focuses on the objects that developers want to manipulate rather than the logic required to manipulate them. This approach to programming is well-suited for programs that are large, complex and actively updated or maintained. This includes programs for manufacturing and design, as well as mobile applications; for example, OOP can be used for manufacturing system simulation software. The organization of an object-oriented program also makes the method beneficial to collaborative development, where projects are divided into groups. Additional benefits of OOP include code reusability, scalability and efficiency. The first step in OOP is to collect all of the objects a programmer wants to manipulate and identify how they relate to each other -- an exercise known as data modeling. Examples of an object can range from physical entities, such as a human being who is described by properties like name and address, to small computer programs, such as widgets. Once an object is known, it is labeled with a class of objects that defines the kind of data it contains and any logic sequences that can manipulate it. Each distinct logic sequence is known as a method. Objects can communicate with well-defined interfaces called messages. What is the structure of object-oriented programming?The structure, or building blocks, of object-oriented programming include the following:
What are the main principles of OOP?Object-oriented programming is based on the following principles:
What are examples of object-oriented programming languages?While Simula is credited as being the first object-oriented programming language, many other programming languages are used with OOP today. But some programming languages pair with OOP better than others. For example, programming languages considered pure OOP languages treat everything as objects. Other programming languages are designed primarily for OOP, but with some procedural processes included. For example, popular pure OOP languages include:
Programming languages designed primarily for OOP include:
Other programming languages that pair with OOP include:
What are the benefits of OOP?Benefits of OOP include:
Criticism of OOPThe object-oriented programming model has been criticized by developers for multiple reasons. The largest concern is that OOP overemphasizes the data component of software development and does not focus enough on computation or algorithms. Additionally, OOP code may be more complicated to write and take longer to compile. Alternative methods to OOP include:
Most advanced programming languages enable developers to combine models, because they can be used for different programming methods. For example, JavaScript can be used for OOP and functional programming. Developers who are working with OOP and microservices can address common microservices issues by applying the principles of OOP. This was last updated in July 2021 Continue Reading About object-oriented programming (OOP)
Dig Deeper on Application development and design
What are various characteristics of an object?All individual objects possess three basic characteristics -- identity, state and behavior. Understanding these characteristics is crucial to knowing how objects and object-oriented logic work. Identity means that each object has its own object identifier and can be differentiated from all other objects.
Which term describes a set of instructions that lists steps that must be followed in a particular order starting at the beginning and continuing to the end?syntax. The set of rules that must be followed when writing program instructions for a specific programming language is called: Structured.
What are the characteristics of an object in OOP?Object-oriented methodology relies on three characteristics that define object-oriented languages: encapsulation, polymorphism, and inheritance.
How are the characteristics of an object represented in a class?The object of a class is represented through the attributes. The term instantiation is used for creating various objects. Class is a blueprint of the objects. new keyword indicates an operator for dynamic allocation of an object.
|