I have never done a course on VBA so I feel I lack understanding of certain concepts.
- I am looking for a concise definition & explanation of Early Binding & Late Binding.
- What is the pros & cons of each method?
I have never done a course on VBA so I feel I lack understanding of certain concepts.
- I am looking for a concise definition & explanation of Early Binding & Late Binding.
- What is the pros & cons of each method?
*******************************************************
HELP WANTED! (Links to Forum threads)
Trying to create reusable code for Custom Events at Workbook (not Application) level
*******************************************************
In early binding, the VBA project includes a reference to the library where the methods and properties of (non-native VBA) objects are defined, so object variables may be defined and instantiated as the objects they will reference (e.g., Dim oDoc as Word.Document, Set oDoc = New Word.Document). Because objects are known at compile time, Intellisense works, and it's faster at runtime because references to properties and methods are linked to the known entry points. When referencing a library, you are, perforce, specifying a version, e.g., Word 12.
In late binding, there is no reference, and object variables are declared as Object (or, less strongly, as Variant). Intellisense doesn't work because the compiler hasn't a clue what they are. Object variables are instantiated with CreateObject() or GetObject(). At runtime, the VTable must be searched to locate the entry point for the property or method. An advantage is that it loads whatever library is most recent, so if it can't find Word 12, it will load Word 10, which affords a level of flexibility, especially if the code is being deployed to multiple computers.
Last edited by shg; 02-08-2013 at 01:28 PM.
Entia non sunt multiplicanda sine necessitate
You're welcome.
strictly speaking of course it is simply the declaration as Object or specific object type that determines the binding and not the method of instantiation. you can late bind even with a reference set-though not vice versa!
Josie
if at first you don't succeed try doing it the way your wife told you to
what I mean is that
is late binding even if you are in Excel or if you have a reference set to the excel object library, and regardless of whether you then usePlease Login or Register to view this content.
orPlease Login or Register to view this content.
to actually initialize the variablePlease Login or Register to view this content.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks