+ Reply to Thread
Results 1 to 8 of 8

Seeking knowledge on Early Binding, Late Binding

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Lightbulb Seeking knowledge on Early Binding, Late Binding

    I have never done a course on VBA so I feel I lack understanding of certain concepts.
    1. I am looking for a concise definition & explanation of Early Binding & Late Binding.
    2. 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

    *******************************************************

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Seeking knowledge on Early Binding, Late Binding

    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

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Seeking knowledge on Early Binding, Late Binding

    Quote Originally Posted by shg View Post
    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.
    This is the sort of explanation I was looking for! Thank you.

    In short, I take it that:
    Early Binding = faster & tighter/explicit
    Late Binding = slower & flexible

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Seeking knowledge on Early Binding, Late Binding

    You're welcome.

  5. #5
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Seeking knowledge on Early Binding, Late Binding

    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

  6. #6
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Seeking knowledge on Early Binding, Late Binding

    Quote Originally Posted by JosephP View Post
    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!
    So the early/late is referring to the object declaration method? I'm afraid you lost me on the next bit...

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Seeking knowledge on Early Binding, Late Binding

    what I mean is that
    Please Login or Register  to view this content.
    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 use
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    to actually initialize the variable

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Seeking knowledge on Early Binding, Late Binding

    Quote Originally Posted by JosephP View Post
    what I mean is
    Got it! Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1