Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Early Binding (Excel2003 VBA)

    (sorry if this a double post - I lost the first try, maybe I submitted, maybe I didn't)

    Have code that uses MS Outlook. For some people this creates errors on sheet-load. I recall stuff about early & late binding. How do I use late bindig so I do not get the errors anymore and how do I check if the right DLL's can be found?

    Here's piece of different routines in one sheet (they are different I know, but both work and were assemble from existing stuff):

    The first:
    <pre> Sub A()
    Dim OLF As Outlook.MAPIFolder, olMailItem As Outlook.MailItem, ToContact As Recipient
    Set OLF = GetObject("", "Outlook.Application").GetNamespace("MAPI").GetDef aultFolder(olFolderInbox)
    Set olMailItem = OLF.Items.Add ' creates a new e-mail message
    ...
    </pre>

    The second:
    <pre> Sub B()
    Dim olApp As New Outlook.Application
    Dim olDL As Outlook.DistListItem
    Dim olMail As Outlook.MailItem
    Dim olRec As Outlook.Recipient
    '
    Dim olNsp As NameSpace
    Dim olFld As MAPIFolder
    Dim olItm As Object
    ...
    </pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Early Binding (Excel2003 VBA)

    1) You must declare all the Outlook variables as Object instead of as Outlook.ThisOrThat. For example

    Dim OLF As Outlook.MAPIFolder

    becomes

    Dim OLF As Object

    This also holds for the variables that are Outlook objects implicitly (where you omitted Outlook in the declaration). For example

    Dim olNsp As NameSpace

    becomes

    Dim olNsp As Object

    2) You cannot use the New keyword. Use CreateObject instead:

    Dim olApp As New Outlook.Application

    becomes

    Dim olApp As Object
    Set olApp = CreateObject("Outlook.Application")

    Note: you can test whether this is successful:

    Dim olApp As Object
    On Error Resume Next
    Set olApp = CreateObject("Outlook.Application")
    If olApp Is Nothing Then
    MsgBox "Outlook cannot be opened!", vbCritical
    Exit Sub
    End If
    On Error GoTo ErrHandler

    where ErrHandler is your error handler label.

    3) Replace symbolic Outlook constants such as olFolderInbox with their values. You can find these values in the Object Browser while you still have a reference to the Outlook object library.

    4) Remove the reference to the Microsoft Outlook 11.0 Object Library in Tools | References...

    5) Select Debug | Compile VBA Project to see whether you converted everything correctly.

    6) Run and test the code.

  3. #3
    5 Star Lounger
    Join Date
    Jul 2001
    Location
    Terneuzen, Netherlands
    Posts
    895
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Early Binding (Excel2003 VBA)

    Did this and it works (is even relatively easy to do) - thank you!

Posting Permissions

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