Cell Value in Email Body?

Willie03

Board Regular
Joined
Jun 21, 2013
Messages
50
Hello,

I have this code but and I can't this out: it just keeps looping and doesn't stop... Its also not inserting the signature in each email...

Can someone let me know what I am doing wrong please?



Code:
Sub Notify()    Dim name, email, evnt, status As Range
    Dim SigString As String
    Dim Signature As String
    Dim last_row As Integer
    Dim LastRow As Long
    
    LastRow = Range("C2:C200").End(xlDown).Row


        SigString = Environ("appdata") & _
                "\Microsoft\Signatures\Will.txt"


    If Dir(SigString) <> "" Then
        Signature = GetBoiler(SigString)
    Else
        Signature = ""
    End If


    For Each name In Range(("B2"), Range("B2").End(xlDown))
        For Each email In Range(("C2"), Range("C2").End(xlDown))
            For Each evnt In Range(("E2"), Range("E2").End(xlDown))
                For Each status In Range(("F2"), Range("F2").End(xlDown))


    On Error Resume Next


        With CreateObject("Outlook.Application").CreateItem(0)
            .To = email.Value
            .CC = email.Offset(0, 1).Value
            .Subject = "Information You Requested"
            .Body = "Dear " & name.Value & "," & vbNewLine & vbNewLine & _
                "As you may know the 2014 race started on November 4th and will be open until November 15th in order for you to select your candidate." & vbNewLine & vbNewLine & _
                "Your 2014 election is now On Hold since you have a previous " & evnt.Value & " event with a " & status.Value & " status in Workday. " & vbNewLine & vbNewLine & _
                "In order for you to be able to finalize your Elections you need to finalize the event above as soon as possible." & vbNewLine & vbNewLine & _
                "If you have any questions about this task please call us at 1-877-777-7777 option 8" & vbNewLine & vbNewLine & _
                "Regards" & vbNewLine & vbNewLine & _
                "Department"
            .Display
            '.Attachments.Add "C:\test.txt"
            '.Send
            End With
            
                Next
            Next
        Next
    Next
    
End Sub


Function GetBoiler(ByVal sFile As String) As String
    '**** Kusleika
    Dim fso As Object
    Dim ts As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
    GetBoiler = ts.readall
    ts.Close
End Function
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi,

It seems to me that looping is caused by your 4 nested For loops
Code:
    For Each Name In Range(("B2"), Range("B2").End(xlDown))
        For Each Email In Range(("C2"), Range("C2").End(xlDown))
            For Each evnt In Range(("E2"), Range("E2").End(xlDown))
                For Each Status In Range(("F2"), Range("F2").End(xlDown))
If there are 5 values in B, 6 in C, 4 in E and 8 in F, this would create 5*6*4*8 = 960 emails; is that what you wanted?
Also it seems weird to me that you are addressing the same name with all email addresses found, usually one name is connected to one email.
Please explain what it is you want to have done.

I do not know how to have the signature added using vba, except from putting it into the code.
I think Outlook is normally entering the signature in the body before you get a change to fill in your text; It does not add it after pressing Send.
If I'm correct, you should hard-code your signature in your vba.

Succes,

Paul
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

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