+ Reply to Thread
Results 1 to 4 of 4

Dumb early binding question

  1. #1
    Nicole Seibert
    Guest

    Dumb early binding question

    Okay... here goes:

    Do you have to use CreateObject with set in early binding? For instance, I
    have this lovely bit of code:

    Set OutApp = Outlook.Application
    Set xl = Excel.Application
    Set data = xl.Workbooks("Time Exception Master Data")

    Is this consider early binding? Should I instead say "Get" and then the
    document path? I am confused.

    Thanks,
    Nicole

  2. #2
    Tushar Mehta
    Guest

    Re: Dumb early binding question

    Early binding is when you tell the compiler up front what kind of objects
    you will be using. This is done in the VBE through Tools | References...

    In your example, use the above menu item to see if you have references to
    Excel and Outlook. That will tell you whether you are or are not using
    early binding.

    [Actually, if you get set outapp=outlook.application to compile you are
    using early binding. But, the Tools | References... is the first place I
    would look.]

    With early binding you can use set xl=excel.application or you can use
    getobject and/or createobject. With late binding since the compiler doesn't
    know the type of xl, you must use getobject and/or createobject.

    You may want to see

    Early and Late Binding
    http://msdn2.microsoft.com/en-us/library/0tcf61s1.aspx

    CreateObject Function (Visual Basic)
    http://msdn2.microsoft.com/en-us/library/7t9k08y5.aspx

    GetObject Function (Visual Basic)
    http://msdn2.microsoft.com/en-us/library/e9waz863.aspx

    While in most cases early binding is the preferred way to go, there are
    instances when late binding is better. But, for learning purposes, early
    binding is definitely the correct approach.

    --
    Regards,

    Tushar Mehta
    www.tushar-mehta.com
    Excel, PowerPoint, and VBA add-ins, tutorials
    Custom MS Office productivity solutions

    In article <[email protected]>,
    [email protected] says...
    > Okay... here goes:
    >
    > Do you have to use CreateObject with set in early binding? For instance, I
    > have this lovely bit of code:
    >
    > Set OutApp = Outlook.Application
    > Set xl = Excel.Application
    > Set data = xl.Workbooks("Time Exception Master Data")
    >
    > Is this consider early binding? Should I instead say "Get" and then the
    > document path? I am confused.
    >
    > Thanks,
    > Nicole
    >


  3. #3
    Tim Williams
    Guest

    Re: Dumb early binding question

    Early / late binding is more a question of how you define your variables.

    Dim objOL as Object 'late
    Dim objOL as Outlook.Application 'early

    Set objOL = CreateObject("Outlook.Application") 'same for both

    Benefits of early binding include getting Intellisense when writing your code: drawbacks include having to add a refence to the
    library in your project.

    see:
    http://msdn.microsoft.com/archive/de...html/SF7A4.asp
    http://www.*****-clicks.com/excel/olBinding.htm


    Tim

    "Nicole Seibert" <[email protected]> wrote in message
    news:[email protected]...
    > Okay... here goes:
    >
    > Do you have to use CreateObject with set in early binding? For instance, I
    > have this lovely bit of code:
    >
    > Set OutApp = Outlook.Application
    > Set xl = Excel.Application
    > Set data = xl.Workbooks("Time Exception Master Data")
    >
    > Is this consider early binding? Should I instead say "Get" and then the
    > document path? I am confused.
    >
    > Thanks,
    > Nicole




  4. #4
    NickHK
    Guest

    Re: Dumb early binding question

    As others have pointed out, in order to use Early Binding, you have to set a
    reverence to the library you wish to use. Then you can declare your object
    variable as the types you wish use. e.g.
    Dim OApp as Outlook.Application
    'Assuming this is in Excel VBA, you already have a reference to the Excel
    library, so this will work.
    Dim WS As Worksheet

    You now get the benefit of Intellisense, as the compiler knows the possible
    methods/properties etc of the objects you are using.
    If you want to use "With Events", you must use early binding.
    Also, early binding ties you to a specific version of the library, to some
    extent. AFAIK Excel (and other apps) will update the references to new
    versions if available, but not update to older versions. If you need you
    code to work on multiple versions of the same application, reference and
    compile on the oldest version, or use late binding.

    You can still write
    Dim OApp as Object
    but it is a waste, as the compiler now cannot tell which object you are
    referring to, your reference serves little purpose.

    Using late binding (i.e. no reference set) everything can only be declared
    "Object"
    Dim OApp as Object

    How you instantiate your variables is a separate question.
    "GetObject" uses an existing instance of the object.
    "CreateObject" starts a new instance your object, if possible. You cannot
    create multiple instances of some object (Outlook.Application,
    Illustrator.Application, amongst others).
    "New" basically the same as CreateObject, apart from some obscure
    differences in which initialisation code runs, AFAIK.

    NickHK

    "Nicole Seibert" <[email protected]> wrote in message
    news:[email protected]...
    > Okay... here goes:
    >
    > Do you have to use CreateObject with set in early binding? For instance,

    I
    > have this lovely bit of code:
    >
    > Set OutApp = Outlook.Application
    > Set xl = Excel.Application
    > Set data = xl.Workbooks("Time Exception Master Data")
    >
    > Is this consider early binding? Should I instead say "Get" and then the
    > document path? I am confused.
    >
    > Thanks,
    > Nicole




+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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