Return to VBA Code Examples

VBA – Early Late Binding

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on February 22, 2023



Whenever you assign an object to an object variable, VB performs a process called binding. Objects can be early bound or late bound. It’s easy to tell the difference: If you declare a variable as Object, you are late binding. Early binding allows the compiler to perform other optimizations and allocate memory before an application executes, allowing the your code to run much faster. However, Late binding may be desirable In some instances.

Examples:

'Early Binding
Sub earlybinding()
'Create variable to hold new Excel App
Dim xlApp As Excel.Application
'Assign Excel App to variable
Set xlApp = New Excel.Application

'Add Workbook to xlApp & Make xlApp Visible
xlApp.Workbooks.Add
xlApp.Visible = True


End Sub
'Late Binding
Sub latebinding()

'Create variable to hold new object
Dim xlApp As Object
'Assign Excel app to Object
Set xlApp = CreateObject("Excel.Application")

'Add Workbook to xlApp & Make xlApp Visible
xlApp.Workbooks.Add
xlApp.Visible = True
End Sub

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro – A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!

alt text

Learn More!


<<Return to VBA Examples

vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples