Allow automatic sending of email with Outlook

Asked

Viewed 3,074 times

2

Hello, I need to send several emails to different addresses automatically, but when the VBA starts the sending process opens an alert box requesting 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 range in the body of 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
  • Hello. Enter the code you are using to send the emails on the question so we can help you.

  • Someone???????????????

  • This code didn’t help much. You just put the Send Emails function, we need to know how you’re using the sub function, a functional example.

  • sub qualquer enviar_email = Enviar_dados_celulas_email("any subject", [email protected], Range("A1:I17"), "follows example") end sub

  • this hard t D:

  • someone by Please

Show 1 more comment

1 answer

1

Here it worked normal without any notification window, with the code 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

any sub:

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 open, sent automatic; In any case try to use the Application.ScreenUpdating = False and Application.DisplayAlerts = False before executing the function (in the sub) and at the end don’t forget to change to True.

  • Man, I think that because my email is from the company and has firewall that I am having this problem... had already tried display Alerts I managed to send without permission alert with another sending method, but in this new way, I’m not getting a range on the body of the email. D:

  • Edit the question with this second way, to see if we can help you in the problem.

  • Already edited, kept the two codes, thank you.

  • Hold on, help me please D=

Browser other questions tagged

You are not signed in. Login or sign up in order to post.