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

Hello,

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"
.Send
End With

Sheets("CONTROL").Select

End Sub

I get the following error message in relation to olMailItem

Compile Error:

Can't find project or library

Could someone please assist?

Thanks.
f19lAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
MichaelConnect With a Mentor Business AnalystCommented:
Hi there,

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

Open in new window

to
Set olMail = olApp.CreateItem(0)

Open in new window

This works for me in Excel 2010.

Joop
0
 
GrahamSkanRetiredCommented:
You will need to set a reference to the Microsoft Outlook Object Library (Tools/References in the VBA IDE)
0
 
f19lAuthor Commented:
I have a reference already set to Microsoft Outlook 14.0 Object Library.
0
 
f19lAuthor Commented:
It works for me as well. Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.