Hello,
I have code in place to send emails and I cannot seem to figure out why I am receiving an error.
The error that pops up says "User-defined type not defined". The code seems to stop at the line that is highlighted in red below. Any help would be greatly appreciated.
I have code in place to send emails and I cannot seem to figure out why I am receiving an error.
The error that pops up says "User-defined type not defined". The code seems to stop at the line that is highlighted in red below. Any help would be greatly appreciated.
Code:
Sub Macro2()
'
' Macro2 Macro
'
Dim Response As VbMsgBoxResult
Response = MsgBox("Are you sure you want to send the emails?", vbQuestion + vbYesNo)
If Response = vbNo Then Exit Sub
Range("B4").Select
SendEmails:
ActiveCell.Offset(1, 0).Select
If IsEmpty(ActiveCell) Then Exit Sub
On Error GoTo SendEmail
[COLOR=#ff0000][B]Dim aOutlook As Outlook.Application, aEmail As Outlook.MailItem
[/B][/COLOR]Set aOutlook = GetObject(, "Outlook.Application")
If aOutlook Is Nothing Then Set aOutlook = New Outlook.Application
Set aEmail = aOutlook.CreateItem(olMailItem)
aEmail.Subject = ActiveCell.Offset(0, 1)
aEmail.Body = Range("N5") & Chr(13) & Chr(13) & Range("N6") & Chr(13) & Chr(13) & Range("N7") & Chr(13) & Chr(13) & Range("N8") & Chr(13) & Range("N9") & Chr(13) & Range("N10") & Chr(13) & Range("N11") & Chr(13) & Range("N12")
aEmail.Attachments.Add ActiveCell.Offset(0, 2).Text
aEmail.Recipients.Add ActiveCell.Text
aEmail.Recipients.Add ActiveCell.Offset(0, 3).Text
aEmail.Recipients.Add ActiveCell.Offset(0, 4).Text
aEmail.Recipients.Add ActiveCell.Offset(0, 5).Text
aEmail.Recipients.Add ActiveCell.Offset(0, 6).Text
aEmail.Recipients.Add ActiveCell.Offset(0, 7).Text
aEmail.Recipients.Add ActiveCell.Offset(0, 8).Text
aEmail.Recipients.Add ActiveCell.Offset(0, 9).Text
aEmail.Recipients.Add ActiveCell.Offset(0, 10).Text
aEmail.Recipients.Add ActiveCell.Offset(0, 11).Text
SendEmail:
aEmail.Send
Resume SendEmails
MessageBox:
MsgBox "All emails have been sent", vbInformation
'
End Sub