Oprichnick
Board Regular
- Joined
- May 30, 2013
- Messages
- 69
Hello,
I'm trying to build a code that sends each sheet in another workbook as an attachment via outlook.
Each sheet to a different set of emails.
Although I don't get any error message, the emails aren't sent.
With my few vba knowledge I tried to work pieces of code I found. So I guess that some code is not written in the more orthodox way.
Thanks
I'm trying to build a code that sends each sheet in another workbook as an attachment via outlook.
Each sheet to a different set of emails.
Although I don't get any error message, the emails aren't sent.
With my few vba knowledge I tried to work pieces of code I found. So I guess that some code is not written in the more orthodox way.
Code:
Option ExplicitSub RunOnAll()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Mail_small_Text_Outlook ws
Next ws
End Sub
Sub Mail_small_Text_Outlook(ws As Worksheet)
Dim OutApp As Object
Dim OutMail As Object
Application.ScreenUpdating = False
Set OutApp = CreateObject("Outlook.Application")
On Error GoTo cleanup
With Workbooks("DLQ.xls")
For Each ws In .Sheets
If ws = "peter" Then
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = "pedrodomingosdavid@hotmail.com"
.Subject = "Personal report"
.Body = "Regards."
.Attachments.Add Sheets("peter").Copy
.Display
End With
ElseIf ws = "john" Then
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = "pedrodomingosdavid@hotmail.com"
.Subject = "Personal report"
.Body = "Regards."
.Attachments.Add Sheets("john").Copy
.Display
End With
End If
Next ws
End With
cleanup:
Set OutApp = Nothing
Application.ScreenUpdating = True
End Sub
Thanks