[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2013-11-12
3
Medium Priority
?
270 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 37

Expert Comment

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

Accepted Solution

by:
Michael earned 2000 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

New style of hardware planning for Microsoft Exchange server.
Microsoft has changed the look and feel of Azure AD and Microsoft account sign-in pages so that you will have a more unified look and feel when moving between the two interfaces.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

872 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