Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - Understanding Object Binding in VBA
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Understanding Object Binding in VBA
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2009-07-22

    Table of Contents:
  • Understanding Object Binding in VBA
  • Early Binding
  • Late Binding
  • An object lesson

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Understanding Object Binding in VBA - Late Binding


    (Page 3 of 4 )

    The second method of instantiating objects is known as late binding.  In late binding, a reference to the object is not provided to the application; instead, instantiation is made through an object's IDispatch interface at the time of execution.  This is the type of object instantiation used by the Windows Script Host environment, which doesn't provide support for object references.

    Since the object's type library is not processed prior to execution, the object's exposed interfaces are not available.  This means two things as far as we're concerned.  First, we cannot declare a variable of that type.  Second, we will not be able to instantiate the object by its interface.

    Since the variable we'll be using for our object cannot be declared by the object type, we'll simply declare it as a generic type Object.  Without an interface by which to instantiate it, we'll forgo the New syntax and use VBA's CreateObject method instead.  To do that you'll need to know the ProgId for the COM object you wish to use.  In this case, the ProgId for the Microsoft Excel Object Library is "Excel.Application."

    Dim objExcel As Object

    Set objExcel = CreateObject("Excel.Application")

    Those familiar with the Windows Script Host will find this syntax very familiar, as it is quite close to its WSH equivalent.

    Instantiating objects in this way negates any need to have references in your application, but it also provides a few other distinct advantages.  Let's take a moment to examine the pros and cons of both early and late binding so you know when to use each of them.

    More Visual Basic.NET Articles
    More By Nilpo


     

    VISUAL BASIC.NET ARTICLES

    - Clocks and Countdowns
    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...





    © 2003-2010 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek