Allow automatic sending of emails with Outlook

2

Hi, I need to send multiple emails to different addresses automatically, but when VBA starts the send process it opens an alert box asking for my permission to complete the task.

Does anyone know how to override this alert and send the email?

The email sending code:

Function Enviar_dados_celulas_email(subject As String, destiny As String, body As Range, introductin As String)

' selecão da planilha desejada.
If destiny <> "" Then
    body.Select
    ActiveWorkbook.EnvelopeVisible = True
End If

   With ActiveSheet.MailEnvelope
      .Introduction = introductin
      .Item.To = destiny
      .Item.subject = subject
      .Item.Send
   End With
[D1].Select


End Function

I have this other way, but I can not send a range in the corppo of the email D:

Function Enviar_dados_celulas_email(subject As String, destiny As String, body As Range, introduction As String)

Dim oOutlookApp As Object, oOutlookMessage As Object
Set oOutlookApp = CreateObject("Outlook.Application")
Set oOutlookMessage = oOutlookApp.CreateItem(0)

With oOutlookMessage
    .subject = subject
    .To = destiny
    .body = body
    .Display
     SendKeys "%e"
End With

Set objMsg = Nothing

End Function
    
asked by anonymous 28.04.2015 / 19:20

1 answer

1

Here it worked normal with no notification window, with the code that you provided:

Function Enviar_dados_celulas_email(subject As String, destiny As String, body As Range, introductin As String)

' selecão da planilha desejada.
If destiny <> "" Then
    body.Select
    ActiveWorkbook.EnvelopeVisible = True
End If

   With ActiveSheet.MailEnvelope
      .Introduction = introductin
      .Item.To = destiny
      .Item.subject = subject
      .Item.Send
   End With
[D1].Select

End Function

sub any:

Sub qualquer()

enviar_email = Enviar_dados_celulas_email("qualquer assunto", "[email protected]", Range("A1:A2"), "segue exemplo")

End Sub

Maybe because I was already with the outlook opened, sent automatic; In any case try to use Application.ScreenUpdating = False and Application.DisplayAlerts = False before executing the function (in the sub) and in the end do not forget to switch to True .

    
28.04.2015 / 23:26