Resting Anchor

The Anchorage

Personal website of Gregory K. Maxey, Commander USN (Retired)

Early vs. Late Binding
(A Microsoft Word Help & Tip page by Gregory K. Maxey)

DISCLAIMER/TERMS OF USE

The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!


The purpose of this Microsoft Word Tips & Microsoft Word Help page is explain and demonstrate Early and Late binding OLE Automation techniques to control and use one application from another.

Early Binding

An object is early bound when it is assigned to a variable declared to be of a specific object type (e.g., Excel.Application). Early bound objects allow the VB compiler to allocate memory and perform other optimizations before an application executes.

To use early binding, you must set a reference to the object type in your VBA project.

early_vs_late_binding_1

Use the following declaration and code to create an instance of Excel:

Advantages of Early Binding

Let's look at a functional example of early binding. Illustrated below is code in a Word project that:

early_vs_late_binding_2

I am not very familiar with the Excel object model.  However, since I used early binding, I was able to leverage its advantages to create this example. For instance:

early_vs_late_binding_3

early_vs_late_binding_3

early_vs_late_binding_5

early_vs_late_binding_6

It should be clear that early binding makes it much easier to write and compile code.

Late Binding

An object is late bound when it is assigned to a variable declared to be of type Object. Objects of this type can hold references to any object, but lack many of the advantages of early-bound objects.

With Late binding, GetObject, CreateObject or both can be used.  For example you could get and control an instance of Excel from Word using the following declaration and code:

Advantages of Late Binding

Summary

Which method to use after comparing the two is a personal choice.  Personally, I typically prepare my projects using early binding in order to take advantage of the automatic code completion and dynamic help.  Then prior to publishing or distribution I shift to late binding to leverage the version independence.

That's it! I hope you have found this tips page useful and informative.

Share

PAYMENTS/DONATIONS

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

Do you want to make a payment for consulting work or donate to help support this site?

PayPal is a safe, easy way to pay online.

Use the appropriate currency "Donate" button to make a payment or donation.


Search my site or the web using Google Search Engine

Google Search Logo