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

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

I am trying to run the following code in excel 2010 but keep getting an error message reading:

Compile error:

Can't find project or library

The problem is due to the "ForReading" part of the code below.

Sub Email_Loan_Rates()
On Error Resume Next

Application.DisplayAlerts = False

Dim olApp As Outlook.Application, olMail As Outlook.MailItem
Dim FSObj As Scripting.FileSystemObject, TStream As Scripting.TextStream
Dim rngeSend As Range, strHTMLBody As String
Dim totalsum1 As String
Dim totalsum2 As String
Dim totalsum3 As String
Dim totalsum4 As String

'Set the range to be sent
Set rngeSend = ActiveSheet.Range("B70:R129")

'Now create the HTML file
ActiveWorkbook.PublishObjects.Add(xlSourceRange, "\\EMEA\Root\Shared2\London Rates\Middle Office\Favourites\sht.htm", rngeSend.Parent.Name, rngeSend.Address, xlHtmlStatic).Publish True

'Create an instance of Outlook (or use existing instance if it already exists)
Set olApp = CreateObject("Outlook.Application")

'Create a mail item
Set olMail = olApp.CreateItem(0)

'Open the HTML file using the FilesystemObject into a TextStream object
Set FSObj = New Scripting.FileSystemObject
Set TStream = FSObj.OpenTextFile("\\EMEA\Root\Shared2\London Rates\Middle Office\Favourites\sht.htm",ForReading)

'Now set the HTMLBody property of the message to the text contained in the TextStream object
strHTMLBody = TStream.ReadAll

olMail.HTMLBody = strHTMLBody

With olMail
.SentOnBehalfOfName = "London MO - Rates"
.To = Emails_loan
.CC = "London MO - Rates"
.Subject = "Loan Rates " & Application.Text(Now(), "dd-mmm-yyyy")
End With

Range("G64").Value = Range("G83").Value
Range("H64").Value = Range("H83").Value
Range("I64").Value = Range("I83").Value
Range("J64").Value = Range("J83").Value
Range("K64").Value = Range("K83").Value
Range("L64").Value = Range("L83").Value


End Sub


Question by:f19l
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
LVL 35

Expert Comment

ID: 39641411
add a reference to: Microsoft Scriptin Runtime / scrrun.dll

Accepted Solution

Michael earned 500 total points
ID: 39641424
If that's not working, try replacing 'ForReading' with 1

Author Comment

ID: 39641430
That works.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need take combination of numbers out of the list 6 16
Tricky shapes formula part 3 4 32
Lync 2010 Certificate 3 14
VBA Replace Function - What am I missing? 3 22
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…
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

733 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