The email macro I set up didn't work when I referenced the sendto from a cell in sheet 2; I changed it to reference an email address on sheet 1 and it worked with spacing errors.
I need to fix the spacing errors, and I need to be able to pull the email from sheet 2.
Code referencing sheet 2:
Sub MailSped1()
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SndTo As String
With Sheets("Sheet2") 'the debugger highlights this and will not send email'
SndTo = .Range("E7")
End With
Code for email body, which has spacing errors:
With Sheets("Sheet1")
strbody = "Students' points in my class" & vbNewLine & vbNewLine & _
.Range("A41") & .Range("B41") & vbNewLine & _
.Range("A42") & .Range("B42") & vbNewLine & _
.Range("A43") & .Range("B43") & vbNewLine & _
.Range("A44") & .Range("B44")
End With
'I deleted the code in between just to shorten this message'
With OutMail
.To = SndTo
.CC = ""
.BCC = ""
.Subject = "Student 's" & "Points"
.htmlbody = strbody
.Send
End With
Just to test the email I changed the line that was having troubles to reference sheet 1, and although it sent the email; the email had spacing errors.
Here is the email it sent:
Subject line: Students'points
Body Line: Students' points in my class Harley Peterson45 Ratino Sherrod35
I want it to send like this:
Students points in my class
Harley Peterson 45
Ratino Sherrod 35
etc....
Bookmarks