DONUT PROJECT - VBA - Automatizando o Outlook para enviar um e-mail com anexo


O código a seguir pode ser usado para automatizar o Outlook a partir do Excel, Word, Access ou qualquer aplicativo VBA habilitado. Também poderia ser usado em um aplicativo VB6. Ele vai criar uma nova mensagem de e-mail e anexe o arquivo especificado. Em sua forma atual, ele irá exibir essa mensagem para que você verifique antes de clicar em Enviar, no entanto, pode ser facilmente modificado, tal como sugerido no código para enviá-lo imediatamente.

Option Explicit 
 
Sub SendMail() 
     
    Dim olApp As Outlook.Application 
    Dim olMail As Outlook.MailItem 
    Dim blRunning As Boolean 
     
     'get application
    blRunning=True 
    On Error Resume Next 
    Set olApp = GetObject(, "Outlook.Application") 
    If olApp Is Nothing Then 
        Set olApp = New Outlook.Application 
        blRunning=False 
    End If 
    On Error Goto 0 
     
    Set olMail = olApp.CreateItem(olMailItem) 
    With olMail 
         'Specify the email subject
        .Subject = "My email with attachment" 
         'Specify who it should be sent to
         'Repeat this line to add further recipients
        .Recipients.Add "name@host.com
         'specify the file to attach
         'repeat this line to add further attachments
        .Attachments.Add "c:\test.txt" 
         'specify the text to appear in the email
        .Body = "Here is an email" 
         'Choose which of the following 2 lines to have commented out
        .Display 'This will display the message for you to check and send yourself
         '.Send ' This will send the message straight away
    End With 
     
    If Not blRunning Then olApp.Quit 
     
    Set olApp=Nothing 
    Set olMail=Nothing 
     
End Sub


 Série eBook Donut Projects: 

DONUT PROJECT: VBA - Projetos e Códigos de Visual Basic for Applications (Visual Basic For Apllication)eBook - DONUT PROJECT 2024 - Volume 03 - Funções Financeiras - André Luiz Bernardes eBook - DONUT PROJECT 2024 - Volume 02 - Conectando Banco de Dados - André Luiz Bernardes eBook - DONUT PROJECT 2024 - Volume 01 - André Luiz Bernardes



Conheça também:

DONUT PROJECT 2021 - VBA Function:  Como Rastrear o Google Maps (Coordenadas Geográficas) no VBA Excel?

DONUT PROJECT 2021 - VBA Function:  Crie Acrônimos a partir de Strings de Texto

DONUT PROJECT 2021 - VBA Function:  Convertendo uma Matrix num Vetor - Convert Matrix to a Vector

DONUT PROJECT 2021 - VBA Function:  Como tornar o Formulário Transparente no MS Excel?

DONUT PROJECT 2021 - VBA Function:  Faça Buscas no Google a Partir da Célula do MS Excel - Search Google From a Cell

DONUT PROJECT 2021 - VBA Function:  Decompondo um Nome nas Dimensões de uma Matriz

DONUT PROJECT 2021 - VBA Function: Extraindo o Último Sobrenome de um Nome Completo ou a Última Palavra de uma Frase

DONUT PROJECT 2021 - VBA Function:  Extraindo o Segundo Nome de um Nome Completo ou a Segunda Palavra de uma Frase

DONUT PROJECT 2021 - VBA Function: Extraindo o Primeiro Nome ou  a Primeira Palavra de uma Frase

Série Piece of Cake

Séries Donut

Leia também:

eBook: Série DONUT PROJECT 2015: Projetos e Códigos de Visual Basic for Applications - Autor: André Luiz Bernardes

eBook: Série Top 10 Funções: Top 10 Funções VBA para o Microsoft Excel - Autor: André Luiz Bernardes

eBook: Série Funções Poderosas: 13 Funções Poderosas no MS Excel - Autor: André Luiz Bernardes

eBook: Série Visual Basic For Application: Criando Logs de acesso: Dicas e Códigos de Visual Basic for Applications - Autor: André Luiz Bernardes

eBook: Série VBA Tips: Rastrei seus Dashboards, Scorecards, Reports, Relatórios, Planilhas e Aplicações - Dicas e Códigos - Autor: André Luiz Bernardes

eBook: Série Data Science: Big Data, Como? - Autor: André Luiz Bernardes

eBook: Série Smarter Analytic: 5 Previsões de Big Data - Autor: André Luiz Bernardes


Comente e compartilhe este artigo!

brazilsalesforceeffectiveness@gmail.com
Inline image 1

Nenhum comentário:

Postar um comentário

diHITT - Notícias