Send Email Issues...

Willie03

Board Regular
Joined
Jun 21, 2013
Messages
50
I have this macro here that is supposed to send emails to the people on column "C" and CC the people in column "F" and its supposed to attach a file located in my documents.

The issue that I'm having is that it does not display the emails of each of the people on column "C" nor does it attach the file.

NOTE: The attachment is the same for all emails that have to be sent.

Code:
Sub Send_Email()


    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
    Dim cel As Range


    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)


    For Each cel In Range(("C2"), Range("C2").End(xlDown))
        strbody = "Hi there" & vbNewLine & vbNewLine & _
                "My name Is William" & vbNewLine & _
                "I work at Fair" & vbNewLine & _
                "Bye" & vbNewLine & _
                "WH"


        On Error Resume Next
        With OutMail
            .To = cel.Value    '"email.address@fair.com"
            .CC = cel.Offset(0, 3).Value
            .BCC = ""
            .Subject = "Information You Requested"
            .Body = strbody
            .Display
            '.Attachments.Add ("C:\test.txt")
            '.Send
        End With
        On Error GoTo 0
    Next cel


    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Hello,

Do you understand that lines of code with a single quote in front ( ' ) are not executed? They are treated as commentary lines.
 
Upvote 0
- Does the file exist, exactly as mentioned?
- What happens if you put the line On Error Resume Next in commentary?
 
Upvote 0
By the way, I would suggest this more condensed coding:

Code:
Sub Send_Email()

    Dim cel As Range

    On Error Resume Next

    For Each cel In Range(("C2"), Range("C2").End(xlDown))
        With CreateObject("Outlook.Application").CreateItem(0)
            .To = cel.Value    '"email.address@fair.com"
            .CC = cel.Offset(0, 3).Value
            .Subject = "Information You Requested"
            .Body = Replace("Hi there##My name Is William#I work at Fair#Bye#WH", "#", vbNewLine)
            .Display
            .Attachments.Add "C:\test.txt"
            '.Send
        End With
    Next

End Sub
 
Upvote 0
OK now its attaches the file 12 times to the last person on the list.

My list currently has 12 names and it should display each email with the attached file before it is sent.
 
Upvote 0
I cannot reproduce what you are saying. I get 12 different emails, each one with 1 attachment.
Please test again, because for the attachment, first it did not work and later on it did work, while the code did not change.
I suspect that your testing procedure is not adequate.
 
Upvote 0
I honestly don't understand what I am doing wrong. Is it possible for you to show me the code you are using to compare?
 
Upvote 0
It's in post #5 above...
 
Upvote 0
Hello,

Any feedback on this please?
Thanks.
 
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,861
Members
449,411
Latest member
adunn_23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top