'Bypass Outlook Security when sending email via Excel macro
I've done an automatically Reminder to send emails from Excel, triggered by a VBS file (placed in the StartUp folder). When I open my PC, the reminder is triggered and it should send the email, but i have a security error.
This is the Excel Macro:
Sub Email()
Dim aOutlook As Object
Dim aEmail As Object
Dim i As Integer
For i = 1 To 100
If Cells(i, 3).Value = Date And IsEmpty(Cells(i, 7)) Then
Set aOutlook = CreateObject("Outlook.Application")
Set aEmail = aOutlook.CreateItem(0)
aEmail.Importance = 2
aEmail.Subject = ActiveSheet.Cells(i, 4)
aEmail.Body = ActiveSheet.Cells(i, 5)
aEmail.To = ActiveSheet.Cells(i, 6)
aEmail.Send
Cells(i, 7).Value = "Sent: " & Now
End If
Next i
End Sub
This is the VBS file:
Dim xlApp, xlBook
Set wshShell = CreateObject( "WScript.Shell" )
Set xlApp = CreateObject("Excel.Application")
userName = wshShell.ExpandEnvironmentStrings( "%UserName%" )
Set xlBook = xlApp.Workbooks.Open("C:\Users\" + userName + "\Desktop\RM.xlsm", 0, False)
xlApp.Application.Run "Email"
xlBook.Save
xlBook.Close
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
How can I can bypass this error, by adding something more in my macro? 
(I've tried all the codes from google, but none of them work. I also don't want to change nothing on Outlook Settings or Windows Reg.)
Solution 1:[1]
You have a few options:
- Install up-to-date antivirus software (Outlook will not display a prompt then) if you can control the environment where your code runs
- Extended MAPI (C++ or Delphi, does not apply in case of VB script). You can however use a wrapper like Redemption (I am its author) that uses Extended MAPI but is accessible from any language including VBS.
- A product like ClickYes.
See http://www.outlookcode.com/article.aspx?id=52 for a discussion and a list of available options.
Solution 2:[2]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Kiran Maroju |

