Solved

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

Posted on 2013-11-12
3
256 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
3 Comments
 
LVL 35

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

No matter the version of Windows you are using, you may have some problems with Windows Search running too slow or possibly not running at all. Before jumping into how you can solve this issue, just know there are many other viable alternative deskt…
My experience with Windows 10 over a one year period and suggestions for smooth operation
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.
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 …

743 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

13 Experts available now in Live!

Get 1:1 Help Now