Help with stolen code for send mail

rebelgeek

New Member
Joined
Nov 23, 2008
Messages
27
I have added a for/next to this code from a reference on the board. With out the for/next everything works. Add the for/next and it sends the first one only? What am I doing wrong?
Code:
Sub Mail_Text_From_Txtfile_Outlook()
' Is working in Office 2000-2007
    Dim OutApp As Object
    Dim OutMail As Object
    Dim r As Long
 
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
 
    On Error Resume Next
    For r = 2 To 4
        Debug.Print r, Cells(r, 1)
        With OutMail
            .To = Cells(r, 1)
            .CC = ""
            .BCC = ""
            .Subject = "This is the Subject line"
            .Body = "Body text" ' GetBoiler("c:\test.txt")
            .Send   'or use .Display
        End With
    Next r
    On Error GoTo 0
 
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
I would think you have to create a new mail item for each email...so that has to be in the loop to...


For x = 2 to 4
set outmail = ...
...
next x
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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