Problems running macros due to migration from Windows XP Excel 2007 to Windows 7 Enterprise Excel 2010

Posted on 2013-11-11
Last Modified: 2013-11-11

I used to be able to run the following macro in Excel 2007 but can no longer in Excel 2010.

Sub Email_Rates_Update()
Dim olApp As Outlook.Application, olMail As Outlook.MailItem

Dim rngeSend As Range, strHTMLBody As String

Application.DisplayAlerts = False

Set olApp = CreateObject("Outlook.Application")

Set olMail = olApp.CreateItem(olMailItem)

With olMail
.SentOnBehalfOfName = "xxxxx"
.To = "xxxxx"
.Subject = "xxx"
End With


End Sub

I get the following error message in relation to olMailItem

Compile Error:

Can't find project or library

Could someone please assist?

Question by:f19l
  • 2
LVL 76

Expert Comment

ID: 39638474
You will need to set a reference to the Microsoft Outlook Object Library (Tools/References in the VBA IDE)

Author Comment

ID: 39638477
I have a reference already set to Microsoft Outlook 14.0 Object Library.

Accepted Solution

Michael earned 500 total points
ID: 39638479
Hi there,

maybe it works if you change
 Set olMail = olApp.CreateItem(olMailItem)

Open in new window

Set olMail = olApp.CreateItem(0)

Open in new window

This works for me in Excel 2010.


Author Comment

ID: 39638490
It works for me as well. Thanks.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now