VBA – Early and Late Binding Declarations

In a continuation on the subject of Early and Late Binding:

I decided I should provide a few examples of going from Early to Late binding and vice versa and give the necessary VBA Reference Library for Early Binding …

These should be great starting points in knowing which Reference Libraries are required for which Early Binding declarations, and also aid anyone wanting to convert in either direction.

I hope this help a few of you!

These are the Examples provided thus far:

 

Microsoft Access XX.X Object Library

Early Binding Late Binding
Reference Microsoft Access XX.X Object Library
(msacc.olb)
Example Dim oAccess As Access.Application

Set oAccess = New Access.Application

Dim oAccess As Object

Set oAccess = CreateObject(“Access.Application”)

 

Microsoft ActiveX Data Object X.X Library

Early Binding Late Binding
Reference Microsoft ActiveX Data Object X.X Library
(msadoXX.dll)
Example
Connection
Dim oADODBConnection As ADODB.Connection

Set oADODBConnection = New ADODB.Connection

Dim oADODBConnection As Object

Set oADODBConnection = CreateObject(“ADODB.Connection”)

Example
Stream
Dim oADODBStream As ADODB.Stream

Set oADODBStream = New ADODB.Stream

Dim oADODBStream As Object

Set oADODBStream = CreateObject(“ADODB.Stream”)

 

Microsoft ADO Ext. X.X for DDL and Security Object Library

Early Binding Late Binding
Reference Microsoft ADO Ext. X.X for DDL and Security Object Library
(msadox.dll)
Example
Catalog
Dim oCat As ADOX.Catalog

Set oCat = New ADOX.Catalog

Dim oCat As Object

Set oCat = CreateObject(“ADOX.Catalog”)

 

Microsoft DAO 3.6 Object Library

This is a special case as there can be 2 distinct Libraries used here depending on the targetted database!

Early Binding Late Binding
Reference Microsoft DAO X.X Object Library (older mdb)
(daoXXX.dll)
OR
Microsoft Office XX.X Access database engine Object Library (newer accdb & mdb)
(acedao.dll ???)
Example Dim oDAO As DAO.DBEngine

Set oDAO = New DAO.DBEngine

Dim oDAO As Object

On Error Resume Next
Set oDAO = CreateObject(“DAO.DBEngine.120”)
If oDAO Is Nothing Then
Set oDAO = CreateObject(“DAO.DBEngine.36”)
If oDAO Is Nothing Then
Set oDAO = CreateObject(“DAO.DBEngine.35”)
End If
End If

On Error Goto 0
If oDAO Is Nothing Then Exit Sub ‘Function

 

Microsoft Excel XX.X Object Library

Early Binding Late Binding
Reference Microsoft Excel XX.X Object Library
(excel.exe)
Example Dim oExcel As Excel.Application

Set oExcel = New Excel.Application

Dim oExcel As Object

Set oExcel = CreateObject(“Excel.Application”)

 

Microsoft Internet Controls

Early Binding Late Binding
Reference Microsoft Internet Controls
(ieframe.dll)
Example
Internet Explorer
Dim oIE As SHDocVw.InternetExplorer

Set oIE = New SHDocVw.InternetExplorer

Dim oIE As Object

Set oIE = CreateObject(“InternetExplorer.Application”)

 

Microsoft HTML Object Library

Early Binding Late Binding
Reference Microsoft HTML Object Library
(mshtml.tlb)
Example Dim oHTMLDoc As MSHTML.HTMLDocument

Set oHTMLDoc = New MSHTML.HTMLDocument

Dim oHTMLDoc As Object

Set oHTMLDoc = CreateObject(“HTMLFile”)

 

Microsoft PowerPoint XX.X Object Library

Early Binding Late Binding
Reference Microsoft PowerPoint XX.X Object Library
(msppt.olb)
Example Dim oPowerPoint As PowerPoint.Application

Set oPowerPoint = New PowerPoint.Application

Dim oPowerPoint As Object

Set oPowerPoint = CreateObject(“PowerPoint.Application”)

 

Microsoft Scripting Runtime

Early Binding Late Binding
Reference Microsoft Scripting Runtime
(scrrun.dll)
Example
Dictionary
Dim oDictionary As Scripting.Dictionary

Set oDictionary = New Scripting.Dictionary

Dim oDictionary As Object

Set oDictionary = CreateObject(“Scripting.Dictionary”)

Example
FSO
Dim oFSO As Scripting.FileSystemObject

Set oFSO = New Scripting.FileSystemObject

Dim oFSO As Object

Set oFSO = CreateObject(“Scripting.FileSystemObject”)

 

Microsoft Speech Object Library

Early Binding Late Binding
Reference Microsoft Speech Object Library
(sapi.dll)
Example Dim oSpVoice As SpeechLib.SpVoice

Set oSpVoice = New SpeechLib.SpVoice

Dim oSpVoice As Object

Set oSpVoice = CreateObject(“SAPI.SpVoice”)

 

Microsoft Windows Image Acquisition Library vX.X

Early Binding Late Binding
Reference Microsoft Windows Image Acquisition Library vX.X
(wiaaut.dll)
Example
ImageFile
Dim oImageFile                As WIA.ImageFile

Set oImageFile = New WIA.ImageFile

Dim oImageFile               As Object

Set oImageFile = CreateObject(“WIA.ImageFile”)

Example
ImageProcess
Dim oImageProcess As WIA.ImageProcess.

Set oImageProcess = New WIA.ImageProcess

Dim oImageProcess As Object

Set oImageProcess = CreateObject(“WIA.ImageProcess “)

 

Microsoft Windows Installer Object Library

Early Binding Late Binding
Reference Microsoft Windows Installer Object Library
(msi.dll)
Example Dim oMSI As WindowsInstaller.installer

Set oMSI = CreateObject(“WindowsInstaller.Installer”)

Dim oMSI As Object

Set oMSI = CreateObject(“WindowsInstaller.Installer”)

 

Microsoft Word XX.X Object Library

Early Binding Late Binding
Reference Microsoft Word XX.X Object Library
(msword.olb)
Example Dim oWord As Word.Application

Set oWord = New Word.Application

Dim oWord As Object

Set oWord = CreateObject(“Word.Application”)

 

Microsoft XML

Early Binding Late Binding
Reference Microsoft XML, vX.X
(msxml6.dll)
Example Dim oHttp As MSXML2.XMLHTTP60

Set oHttp = New MSXML2.XMLHTTP60

Dim oHttp As Object

Set oHttp = CreateObject(“MSXML2.XMLHTTP.6.0”)

 

Microsoft VBScript Regular Expressions

Early Binding Late Binding
Reference Microsoft VBScript Regular Expressions X.X
(vbscript.dll)
Example Dim oRegEx As VBScript_RegExp_55.RegExp

Set oRegEx = New VBScript_RegExp_55.RegExp

Dim oRegEx As Object

Set oRegEx = CreateObject(“VBScript.RegExp”)

 

Microsoft WinHTTP Services

Early Binding Late Binding
Reference Microsoft WinHTTP Services, version X.X
(winhttpcom.dll)
Example Dim oWinHttp As WinHttp.WinHttpRequest

Set oWinHttp = New WinHttp.WinHttpRequest

Dim oWinHttp As Object

Set oWinHttp = CreateObject(“WinHttp.WinHttpRequest.5.1”)

 

Microsoft WMI Scripting VX.X Library

Early Binding Late Binding
Reference Microsoft WMI Scripting VX.X Library
(wbemdisp.tlb)
Example Dim oWMI As WbemScripting.SWbemServices

Set oWMI = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2”)

Dim oWMI As Object

Set oWMI = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2”)

Note: There are different namespace that can be used ‘\root\cimv2’.
 

Microsoft Script Control 1.0

Early Binding Late Binding
Reference Microsoft Script Control 1.0
(msscript.ocx)
Example Dim oScriptControl As MSScriptControl.ScriptControl

Set oScriptControl = New MSScriptControl.ScriptControl

Dim oScriptControl As Object

Set oScriptControl = CreateObject(“MSScriptControl.ScriptControl”)

Note: Does not work in 64-bit! Refer to: https://github.com/tablacus/TablacusScriptControl
 

Windows Script Host Object Model

Early Binding Late Binding
Reference Windows Script Host Object Model
(wshom.ocx)
Example
WScript.Shell
Dim oWshShell As IWshRuntimeLibrary.WshShell

Set oWshShell = New IWshRuntimeLibrary.WshShell

Dim oWshShell As Object

Set oWshShell = CreateObject(“WScript.Shell”)

Example
WScript.Network
Dim oWshNetwork As IWshRuntimeLibrary.WshNetwork

Set oWshNetwork = New IWshRuntimeLibrary.WshNetwork

Dim oWshNetwork As Object

Set oWshNetwork = CreateObject(“WScript.Network”)

 

Microsoft Shell Controls And Automation

Early Binding Late Binding
Reference Microsoft Shell Controls And Automation
(shell32.dll)
Example Dim oShell As Shell32.Shell

Set oShell = New Shell32.Shell

Dim oShell As Object

Set oShell = CreateObject(“Shell.Application”)

 

3 responses on “VBA – Early and Late Binding Declarations

  1. David Marten

    Nice reference, Daniel!

    The examples in Microsoft WMI Scripting VX.X Library section look incomplete (missing Set …)

  2. James Muka

    Is it possible to use Late Binding on an accde where the main access file is an accde and it references another accde? Our main accde references reports in our sub accde.