Why Build Your Own Objects?

Why Build Your Own Objects?

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

In and of themselves, custom objects do not add new functionality to your code. There is usually another way to arrive at the same result that does not involve creating objects. What they can do is make complex operations appear as simpler, sophisticated applications, more self-documenting and maintainable, and procedures that required hours of coding time more reusable, both for yourself and for other programmers. In fact, creating a custom object is an ideal way to package your code for other Microsoft® Visual Basic® for Applications (VBA) programmers to use, because rather than figuring out how to call your code, they can work with your custom object much as they would with any built-in object.

You can build entire custom object models that involve complex code behind the scenes but present a relatively simple and intuitive object syntax to the programmer. This is, in fact, what all of the Microsoft® Office and VBA object models do for you — they take complex operations and package them into easy-to-use objects, methods, properties, and events. When you set the Visible property of a Microsoft® Excel object to False, for example, you do not have to worry about how VBA, Excel, and Windows cooperate to hide the object. You can focus on the larger-scale goals of building your application.

Naturally, simplicity and reusability come at a price. Creating custom objects and object models requires a different, perhaps even revolutionary, way of thinking than the sort of programming you might be accustomed to doing in VBA. It can take time to get the hang of it. In the long run, though, coding with objects can make you a better programmer by increasing your efficiency, honing your design skills, and making it easier to reuse your code.

See Also

Basic Class Concepts | When Should You Create Custom Objects? | Creating Property Procedures | Creating Events and Event Procedures | Extending Objects Through Interfaces | Designing Object Models | Creating Custom Objects for Web Pages

© 2016 Microsoft