Auto Send a Recurring Email

nanxd

New Member
Joined
May 8, 2015
Messages
16
Hi there,

I am trying to write a code and I actually need help to conclude it.

I am using a code in order to program my outlook to send a recurring e-mail. The problem is: we have a plug-in installed in our outlook that, before sending the e-mail, pops-up window that we need to press "OK".

I'm not succeeding in the code to automate this last part (to automatically press ok). The plugin is called WorkSite and works like file manager and the mesage pretty much asks if we want to store the e-mail on a specific folder.

The code I have written is this:

Private Sub Application_Reminder(ByVal Item As Object)
Dim objPeriodicalMail As MailItem

If Item.Class = olTask Then
If InStr(LCase(Item.Subject), "teste") Then
Set objPeriodicalMail = Outlook.Application.CreateItem(olMailItem)
'Change the following email information as per your actual needs
With objPeriodicalMail
.Subject = "text"
.To = "renan@grt.com"
.HTMLBody = "<HTML>******>text</HTML></BODY>"
.Importance = olImportanceHigh
.ReadReceiptRequested = True
.Send
End With
End If
End If
End Sub


Thank you very much!
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
.
Code:
Option Explicit

'Mass Email From Excel Using VBA Code
Sub Create_Email_From_Excel()
    '‘Below Loop can be changed to While Loop or increase the limit (10) if your list has more than 10 mail ids
    Dim SendTo As String
    Dim ToMSg As String
    Dim i As Integer
 
    For i = 2 To 10
        SendTo = ThisWorkbook.Sheets(1).Cells(i, 1)
        If SendTo <> "" Then
            ToMSg = ThisWorkbook.Sheets(1).Cells(i, 3)
            Send_Mail_From_Excel SendTo, ToMSg
        End If
    Next i
End Sub
Sub Send_Mail_From_Excel(SendTo As String, ToMSg As String)
    Dim OutlookApp As Object
    Dim OutlookMail As Object
 
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
 
    'Send Mass Email Using Excel VBA Macro Code
    With OutlookMail
        .To = SendTo
        .CC = ""
        .BCC = ""
        .Subject = "Happy New Year"
        .Body = ToMSg
        .Display '‘ or just put .Send to directly send the mail instead of display
        
    End With
 
    Set OutlookMail = Nothing
    Set OutlookApp = Nothing
End Sub

Email addresses go in Col A.

Body of message goes in Col C.
 
Upvote 0
.
Code:
Option Explicit

'Mass Email From Excel Using VBA Code
Sub Create_Email_From_Excel()
    '‘Below Loop can be changed to While Loop or increase the limit (10) if your list has more than 10 mail ids
    Dim SendTo As String
    Dim ToMSg As String
    Dim i As Integer
 
    For i = 2 To 10
        SendTo = ThisWorkbook.Sheets(1).Cells(i, 1)
        If SendTo <> "" Then
            ToMSg = ThisWorkbook.Sheets(1).Cells(i, 3)
            Send_Mail_From_Excel SendTo, ToMSg
        End If
    Next i
End Sub
Sub Send_Mail_From_Excel(SendTo As String, ToMSg As String)
    Dim OutlookApp As Object
    Dim OutlookMail As Object
 
    Set OutlookApp = CreateObject("Outlook.Application")
    Set OutlookMail = OutlookApp.CreateItem(0)
 
    'Send Mass Email Using Excel VBA Macro Code
    With OutlookMail
        .To = SendTo
        .CC = ""
        .BCC = ""
        .Subject = "Happy New Year"
        .Body = ToMSg
        .Display '‘ or just put .Send to directly send the mail instead of display
        
    End With
 
    Set OutlookMail = Nothing
    Set OutlookApp = Nothing
End Sub

Email addresses go in Col A.

Body of message goes in Col C.

Thank you for your response.

In fact the code I wrote is working fine, but I can not automate the ok on the popup window that appears before the mesage leaves the outbox.

Do you know how I could do that?
 
Upvote 0
.
I located this macro at this URL :

http://https://www.mrexcel.com/forum/excel-questions/286522-pass-keystrokes-another-program.html

I have not tested it here for accuracy :

Code:
'============================= 
'-  *** PARTIAL CODE ONLY *************
' API PRESS KEY 
'============================= 
Private Sub PressKey(k) 
    Call keybd_event(k, 0, 0, 0)          ' down 
    Call keybd_event(k, 0, VK_KEYUP, 0)   ' up 
    DoEvents 
    DELAY1 
End Sub


Another suggestion:

Perhaps record a macro of you going through the steps of sending an email & clicking on the OK button. See if the macro recorder can give you what you need for code.


Do a Google search for " VBA Pass keystrokes to another program "

(The line "DELAY1" is a call to another macro the author has created, designed to pause the macro for a second or two.)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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