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
Solved

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

Posted on 2013-11-12
3
262 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

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…
PaperPort has a feature called the "Send To Bar". It provides a convenient, drag-and-drop interface for using other installed software, such as Microsoft Office. However, this article shows that the latest Office 2016 apps (installed with an Office …
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 …

828 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