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.)