Email Macro - Compile Error

csch123

New Member
Joined
Mar 6, 2013
Messages
32
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.

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
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Have you set a reference to the relevant Microsoft Outlook object library? (Tools-References in the VB Editor)
 
Upvote 0

Forum statistics

Threads
1,215,137
Messages
6,123,253
Members
449,093
Latest member
Vincent Khandagale

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