andycapp28
Technical User
I have put the code below my issues, it's drawn from other threads I've found.
1.
The FOR loop does not exclude row 2 in Column E(blank email) of my single excel sheet.
2.
I unable to get past the .Attachments.Add it fails to find the files even though I have checked the path.
If I hard code a filename it passes to the sendto.
3.
I get a system administrator bounce back "not received" yet the email address are valid.
4.
It does not seem to be refreshing r.value from column E
Notes;
Column A holds excel filenames I wish to attach to the email address held in Column E
Column A row 2 has 1998GBO.Xls
Column A row 3 has 1995PHO.xls
Column A row 4 has 1998MDE.xls
Column E row 2 has abc@googlemail.com,
E row 3 is blank
E row 4 is andycapp28@googlemail.com
1.
The FOR loop does not exclude row 2 in Column E(blank email) of my single excel sheet.
2.
I unable to get past the .Attachments.Add it fails to find the files even though I have checked the path.
If I hard code a filename it passes to the sendto.
3.
I get a system administrator bounce back "not received" yet the email address are valid.
4.
It does not seem to be refreshing r.value from column E
Notes;
Column A holds excel filenames I wish to attach to the email address held in Column E
Column A row 2 has 1998GBO.Xls
Column A row 3 has 1995PHO.xls
Column A row 4 has 1998MDE.xls
Column E row 2 has abc@googlemail.com,
E row 3 is blank
E row 4 is andycapp28@googlemail.com
Code:
Sub Email_ESS()
'
' Email all supported Evs held in excel file and _
attach his/her file from Monthly Query results
'
Dim r As Range, c As Range
Dim rLookfor As Range
Dim rLookin As Range
With Application
Application.ScreenUpdating = False
Application.EnableEvents = False
End With
With Worksheets
' Set rLookin = Range(Cells(2, "E"), Cells(2, "E").End(xlDown)) TOOK USE of this out as couldn't get to compile
End With
'For Each r In rLookin TOOK THIS OUT, COULDn't use as not get to compile
For Each r In Range(Cells(2, "E"), Cells(2, "E").End(xlDown))
' Set r = rLookin.Find(r.Value) NOT USING (see above)
If Not r Is Nothing Then
ESubject = "ESS_Report"
sendto = r.Value
NewFileName = r.Offset(0, -4)
Set App = CreateObject("Outlook.Application")
Set Itm = App.CreateItem(0)
With Itm
.Subject = ESubject
.to = sendto
.Attachments.Add "G:\Marketing\Management and admin\Monthly Management Reports\ESS & EIT Monthly Reporting\NewFileName"
.Send
End With
Set App = Nothing
Set Itm = Nothing
End If
Next
End Sub