Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
Por marquesdsantos
#58618
Boa tarde!

Tenho o seguinte código que envia e-mail ao fechar a planilha do Excel, mas estou querendo colocar uma opção se a pessoa quiser ou não enviar ao fechar a planilha.
No código tem o .send, tentei colocar mais não consegui.


Public Sub Enviar_Email()

total_linhas = Plan3.Range("S16")
X = Plan3.Range("S17").Text
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet
Set ws = wb.Sheets(X)

For linha = 6 To total_linhas

Dim OutApp As Object
Dim OutMail As Object
Dim texto As String

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

If ws.Cells(linha, 35) = "SIM" Then

With OutMail
.To = Plan3.Range("S15") 'LISTA DE EMAILS
.cc = "" 'CÓPIA
.BCC = ""
.Subject = "Negociação Extraoficial de Pedidos (PCP & Comercial) - Previsão para " & X 'título
.Body = "Prezados," _
& vbNewLine & vbNewLine & _
"Ítens em atraso para atendimento:" & _
vbNewLine & vbNewLine & _
"Data de entrada: " & ws.Cells(linha, 18) & " - " & "Solicitante: " & ws.Cells(linha, 15) & _
vbNewLine & _
"Data de atendimento previsto: " & ws.Cells(linha, 21) & _
vbNewLine & _
"Resp. Autorização: " & ws.Cells(linha, 17) & _
vbNewLine & vbNewLine & _
"Produto: " & ws.Cells(linha, 6) & " Cor: " & ws.Cells(linha, 7) & " - " & ws.Cells(linha, 8) & _
vbNewLine & _
"Mês venda: " & ws.Cells(linha, 9) & " Pedido: " & ws.Cells(linha, 10) & " Ítem: " & ws.Cells(linha, 11) & _
vbNewLine & _
"Lead time de liberação: " & ws.Cells(linha, 34) & " dias" & _
vbNewLine & vbNewLine & _
"(Envio automático: FPCP 01-084 NEGOCIAÇÃO EXTRAOFICIAL DE PEDIDOS - GMM)"
'.HTMLBody = texto
'.Display 'Utilize Send para enviar o email sem abrir o Outlook
.send
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
Else
End If
Next linha
End Sub
Avatar do usuário
Por mucascosta
Posts Avatar
#58821
Código: Selecionar todos
Sub Enviar()
Dim x As Integer
    x = MsgBox("VOCÊ QUER ENVIAR?", vbYesNo + vbQuestion, Title:="© Muca Sistemas - 2020")
If x = vbYes Then
    Enviar_Email
Exit Sub
End If
End Sub
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord