Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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.
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 use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

828 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