Consulting

Results 1 to 9 of 9

Thread: Microsoft Outlook Object Library Reference Missing

  1. #1
    VBAX Regular
    Joined
    Jul 2012
    Posts
    13
    Location

    Microsoft Outlook Object Library Reference Missing

    Hi everyone,

    I need some help so solve this one. I have an excel file that is used by a lot of people in my company but some of us have Excel+Outlook 2013, others 2010 and some still with 2007.

    The porpose of the excel file is to send an email to a list of contacts. After someone with a more recent version of the Office runs the macro, those who have an older version get an error message and shows up the debug window with the vba code.

    The solution we have right now is to manually uncheck the current "Microsoft Outlook Object Library Reference" and check an older version "Microsoft Outlook Object Library Reference".

    However I believe there is a way to go around this but I don't know how.

    Thank you for your help.

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,722
    Location
    You can late bind your code - remove the reference completely, declare all Outlook objects as Object, use GetObject or CreateObject rather than New to initialize the application instance, and make sure you either declare any constants you use from the Outlook object library, or use their literal values instead.
    Be as you wish to seem

  3. #3
    VBAX Regular
    Joined
    Jul 2012
    Posts
    13
    Location
    I'm sorry but I don't get it.

    My code is something like this:

    Dim mess_body As String
        Dim add As String
        Dim appOutLook As Outlook.Application
        Dim MailOutLook As Outlook.MailItem
        Set appOutLook = CreateObject("Outlook.Application")
        Set MailOutLook = appOutLook.CreateItem(olMailItem)
    (...)
    With MailOutLook
            .To = strP
            .CC = strC
            .Subject = "Distribuição do Plano: " + Cells(f, 2) + " (Enc: " + enc + ")"
            .HTMLBody = mess_body
            .Send
    End With
    Could you give an example?

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,722
    Location
    See if this makes it clearer: http://excelmatters.com/?p=69
    There's an Outlook example at the end showing early- vs late-bound versions.
    Be as you wish to seem

  5. #5
    VBAX Regular
    Joined
    Jul 2012
    Posts
    13
    Location
    Thanks a lot for your help.

    However, late binding the code wasn't a solution. I keep having the same error message.

    My code now is like this:
    Dim mess_body As String
    Dim add As String
    Dim appOutLook As Object
    Dim MailOutLook As Object
        
    Const olMailItem As Long = 0
        
    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    (...)
    With MailOutLook
            .To = strP
            .CC = strC
            .Subject = "Distribuição do Plano: " + Cells(f, 2) + " (Enc: " + enc + ")"
            .HTMLBody = mess_body
            .Send
    End With
    I was really hopefull that your sugestion would solve the problem...

    Do you think it has something to do with 2013 MS Office version?

  6. #6
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,722
    Location
    Did you remove the reference to the Outlook library?
    Be as you wish to seem

  7. #7
    VBAX Regular
    Joined
    Jul 2012
    Posts
    13
    Location
    Quote Originally Posted by Aflatoon View Post
    Did you remove the reference to the Outlook library?
    I'm sorry but, how? :-P

  8. #8
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    Tools - References and then unckeck it.

  9. #9
    VBAX Regular
    Joined
    Jul 2012
    Posts
    13
    Location

    Thumbs up

    Thank you guys! It's working nicely.

Posting Permissions

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