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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

813 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

12 Experts available now in Live!

Get 1:1 Help Now