Solved

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

Posted on 2013-11-12
3
264 Views
Last Modified: 2013-11-12
Hello,

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")
.Display
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

Sheets("CONTROL").Select
'ActiveWorkbook.Save
'ActiveWorkbook.Close

End Sub

Thanks,

f19l
0
Comment
Question by:f19l
[X]
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
3 Comments
 
LVL 36

Expert Comment

by:Kimputer
ID: 39641411
add a reference to: Microsoft Scriptin Runtime / scrrun.dll
0
 
LVL 6

Accepted Solution

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

Author Comment

by:f19l
ID: 39641430
That works.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Microsoft Office Picture Manager is not included in Office 2013. This comes as a shock to users upgrading from earlier versions of Office, such as 2007 and 2010, where Picture Manager was included as a standard application. This article explains how…
This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

688 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