PDA

View Full Version : [SOLVED:] Microsoft Outlook Object Library Reference Missing



helderw
11-15-2013, 05:00 AM
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.

Aflatoon
11-15-2013, 07:24 AM
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.

helderw
11-15-2013, 09:35 AM
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?

Aflatoon
11-15-2013, 09:55 AM
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.

helderw
11-15-2013, 11:43 AM
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?

Aflatoon
11-15-2013, 12:53 PM
Did you remove the reference to the Outlook library?

helderw
11-15-2013, 01:07 PM
Did you remove the reference to the Outlook library?

I'm sorry but, how? :-P

JKwan
11-15-2013, 03:09 PM
Tools - References and then unckeck it.

helderw
11-18-2013, 08:07 AM
Thank you guys! It's working nicely. :clap: