How to use excel to send email automaically to me user

ZOL

New Member
Joined
Aug 15, 2011
Messages
21
hi, how do i send email to the users using mt excel file automatically? i have the code i get from the net. but i dunno how to use. they gave me an error when it is at .send. do i have to configure anything? i jus paste the code in my excel. please help, i am new to vba. thanks

Code:
Sub Sendmail()
     
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    sTo = "[EMAIL="whcmelvin@email.com"]whcmelvin@email.com[/EMAIL]"
    sCC = ""
    sBCC = ""
    sSubject = "Overdue"
    strbody = "Good Morning" & vbNewLine & vbNewLine & _
    "Here is a message"
    With OutMail
        .To = sTo
        .CC = sCC
        .BCC = sBCC
        .Subject = sSubject
        .Body = strbody
        .Send
    End With
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 
Sub CheckDue()
    Dim rDates As Range, cl As Range
     
    Set rDates = Sheet1.Range("a1", Range("a65536").End(xlUp))
     
    For Each cl In rDates
        If cl.Value >= Date Then
            sTo = cl.Offset(0, 1).Value 'assumes addresses in Column B
            Call Sendmail
        End If
         
    Next cl
     
     
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Looks like you need to open outlook first and make sure you have outlook referenced. This code works for me.

Code:
Sub Sendmail()
Dim OutApp As New Outlook.Application
Dim OutMail As Outlook.MailItem
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(olMailItem)
    sTo = "EMAIL ADDRESS"
    sCC = ""
    sBCC = ""
    sSubject = "Overdue"
    strbody = "Good Morning" & vbNewLine & vbNewLine & _
    "Here is a message"
    
    OutOpen = True
    Set myExplorer = OutApp.ActiveExplorer
    If TypeName(myExplorer) = "Nothing" Then
        OutOpen = False
        Set myNameSp = OutApp.GetNamespace("MAPI")
        Set myInbox = myNameSp.GetDefaultFolder(olFolderInbox)
        Set myExplorer = myInbox.GetExplorer
    End If
    With OutMail
        .To = sTo
        .CC = sCC
        .BCC = sBCC
        .Subject = sSubject
        .Body = strbody
    End With
    OutMail.Send
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
 
Upvote 0
is it possible to not open outlook and send the email? cos i want it to send automatically. my purpose is that when a user create an account in the excel, a confirmation email will be sent.
 
Upvote 0
do i have to conigure the outlook to an existing email first?
They gave me an error, User Define type not define.
 
Upvote 0
Not sure what you mean. Are you saying that Outlook has not been setup for the user yet?
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,290
Members
452,902
Latest member
Knuddeluff

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