Macro Envio E-mail ...
 
Notifications
Clear all

Macro Envio E-mail via Outlook (Funcionando na versão 2013 mas não na versão 2019 do Outlook)

4 Posts
2 Usuários
0 Likes
1,411 Visualizações
(@lcamargo)
Posts: 6
Active Member
Topic starter
 

Meus amigos, estou com uma macro que envia e-mails via Outlook funcionando muito bem até então.

Acontece que precisei trocar de PC e mudei para versão 2019 do Outlook e macro "parou" de funcionar, sem apresentar um erro. Porém simplesmente não envia mais os e-mails. Alguém sabe me dizer se pode ser uma simples configuração do Outlook ou se preciso mudar alguma coisa no código?

Segue o código:

 

_______

Sub Mail_Selection_Range_Outlook_Body()
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2010
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

Set rng = Nothing
On Error Resume Next
'Only the visible cells in the selection
Set rng = Selection.SpecialCells(xlCellTypeVisible)
'You can also use a range if you want
Set rng = Sheets("MySheet").Range("D4:D12").SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If

With Application
.EnableEvents = False
.ScreenUpdating = False
End With

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

Dim destinatario1 As String
destinatario1 = Sheets("E-Mail Retorno").Range("E2")

Dim destinatario2 As String
destinatario2 = Sheets("E-Mail Retorno").Range("E3")

Dim destinatario3 As String
destinatario3 = Sheets("E-Mail Retorno").Range("E4")

Dim assunto As String
assunto = Sheets("E-Mail Retorno").Range("E5")

On Error Resume Next
With OutMail
.To = destinatario1
.CC = destinatario2
.BCC = destinatario3
.Subject = assunto
.HTMLBody = RangetoHTML(rng)
.Send 'or use .Send or .Display
End With
On Error GoTo 0

With Application
.EnableEvents = True
.ScreenUpdating = True
End With

Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2010
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook

TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

'Copy the range and create a new workbook to past the data in
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With

'Publish the sheet to a htm file
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
Source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With

'Read all data from the htm file into RangetoHTML
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.ReadAll
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")

'Close TempWB
TempWB.Close savechanges:=False

'Delete the htm file we used in this function
Kill TempFile

Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function

_____________________

 

Se alguém puder me ajudar, desde já agradeço.

 
Postado : 17/11/2020 11:35 am
Tags do Tópico
(@teleguiado)
Posts: 142
Estimable Member
 

@lcamargo

Testei o código no office 365 e funcionou, so não enviou pois nao esta configurado no outlook, porem estava na caixa de saída.

Não sei se é mesmo office que você utiliza.

Obrigado.

Teleguiado.
E-mail: telegui4do@gmail.com

 
Postado : 17/11/2020 12:37 pm
(@lcamargo)
Posts: 6
Active Member
Topic starter
 

@teleguiado Estou com o Outlook 2019, provavelmente seja alguma restrição ou limitação desta versão do Outlook

 
Postado : 17/11/2020 1:22 pm
(@lcamargo)
Posts: 6
Active Member
Topic starter
 

Bom dia Pessoal,

 

Com a finalidade de ajudar. Estou compartilhando a planilha que estou querendo rodar no Outlook 2019. Se puderem me ajudar.

 
Postado : 25/11/2020 7:41 am