The Anchorage
Personal website of Gregory K. Maxey, Commander USN (Retired)
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
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.
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.
Use the following declaration and code to create an instance of Excel:
Let's look at a functional example of early binding. Illustrated below is code in a Word project that:
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:
It should be clear that early binding makes it much easier to write and compile code.
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:
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.
The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.
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!