Hi, I am a novice VBAer so please bear with me on this one.
I have a small database in an excel sheet.
My goal is to allow a user to enter data, then select a range and have the data from the range inserted into the body of the email. I want to format the body of the mail so that the data from each row in the range is displayed on its own line.
I am trying to get this code to work:
Private Function SendMail() As Boolean
Dim rngSelected As Range
Dim strtemp As String
Dim intRowCount As Integer
'Let the user select a range
Set rngSelected = Application.InputBox(Prompt:="Please select range you wish to send.", _
intRowCount = rngSelected.Rows.Count
'I want to display the information from each row of the selected range
'and display it on its own line in the message body
'For some reason the For Each statement gives me an error
Dim i As Integer
For i = 1 To intRowCount
For Each cell In rngSelected.Rows(i) ' gives error: can't find project or library
strtemp = strtemp + " " + cell.Value
strtemp = strtemp + vbCrLf 'start a new row
'build my mail message
Dim x As Outlook.Application
Dim y As Outlook.MailItem
Set x = New Outlook.Application
Set y = x.CreateItem(olMailItem)
.Subject = "Whatever"
.To = "[email protected]"
.Body = strtemp
Set x = nothing
Set y = nothing
NOTE: When I enter the word "cell" it does not capitlize automatically like other key words.
I have references to Outlook, Excel and Office 9.0 libraries and am using Excel 2000.
Any help is greatly appreciated.