andycapp28
Technical User
This is continuing on from some code I wrote where an excel spreadsheet had Column E holding email addresses. This column E was read and for each cell containing an address it would select Column A containing name of excel file to be put in an email.
I need to refine this as I need to ensure the excel file in Column A exists and only if it does send an email.
Finally just to ask if .From is valid to use object
My existing code is as follows;
I need to refine this as I need to ensure the excel file in Column A exists and only if it does send an email.
Finally just to ask if .From is valid to use object
My existing code is as follows;
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