Notifications
Clear all

Como envio email pelo VBA

7 Posts
3 Usuários
0 Reactions
1,206 Visualizações
(@wendel)
Posts: 3
Active Member
Topic starter
 

Boa tarde,

Gostaria de saber como faço para enviar um email pelo Lotus usando o excel, pois tenho uma planilha e preciso que ela informe quando um determinado item esta para vencer, gostaria que a rotina enviase o email para a pessoa responsavel pelo item 30 dias antes de vencer.

Exemplo:
Item Validade responsavel
a 20/jun fulano 1
b 30/jun fulano 2
c 12/ago fulano 3
d 10/out fulano 4

Desde já agradeço.

 
Postado : 28/06/2012 2:44 pm
(@robert)
Posts: 561
Honorable Member
 

Wendel,
Boa noite!

Veja se este LINK pode te ajudar.

http://www.exceldoseujeito.com.br/2010/ ... cel-macro/

 
Postado : 28/06/2012 3:20 pm
(@wendel)
Posts: 3
Active Member
Topic starter
 

Robert,

Eu preciso que ele encaminhe somente o item para o seu respectivo responsavel, consegueria me ajudar? eu não conheço muito de VBA.

 
Postado : 28/06/2012 3:32 pm
(@robert)
Posts: 561
Honorable Member
 

Wendel,

Não manjo muito de VBA ainda sou iniciante mais o que posso te aconselhar é tentar utilizar a busca do FÓRUM já vi aqui vários exemplos desse.

Tenta ai cara.

Vlw!

 
Postado : 28/06/2012 3:35 pm
(@robert)
Posts: 561
Honorable Member
 

Vê se te ajuda.

search.php?keywords=vba+mandar+email

 
Postado : 28/06/2012 3:38 pm
(@wendel)
Posts: 3
Active Member
Topic starter
 

Ainda estou tendo problemas para fazer a comunicação do excel, será que alguem consegue me ajudar??

 
Postado : 29/06/2012 1:36 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa noite!!

Consegue adaptar?
Fonte: http://www.ozgrid.com/forum/showthread.php?t=25809

Sub SendWithLotus() 
    Dim noSession As Object, noDatabase As Object, noDocument As Object 
    Dim obAttachment As Object, EmbedObject As Object 
    Dim stSubject As Variant, stAttachment As String 
    Dim vaRecipient As Variant, vaMsg As Variant 
     
    Const EMBED_ATTACHMENT As Long = 1454 
    Const stTitle As String = "Active workbook status" 
    Const stMsg As String = "The active workbook must first be saved " & vbCrLf _ 
    & "before it can be sent as an attachment." 
     'Check if the active workbook is saved or not
     'If the active workbook has not been saved at all.
    If Len(ActiveWorkbook.Path) = 0 Then 
        MsgBox stMsg, vbInformation, stTitle 
        Exit Sub 
    End If 
     'If the changes in the active workbook have been saved or not.
    If ActiveWorkbook.Saved = False Then 
        If MsgBox("Do you want to save the changes before sending?", _ 
        vbYesNo + vbInformation, stTitle) = vbYes Then _ 
        ActiveWorkbook.Save 
    End If 
     'Get the name of the recipient from the user.
    Do 
        vaRecipient = Application.InputBox( _ 
        Prompt:="Please add name of the recipient such as:" & vbCrLf _ 
        & "will@yahoo.co.uk or just the name if internal mail within Unity.", _ 
        Title:="Recipient", Type:=2) 
    Loop While vaRecipient = "" 
     'If the user has canceled the operation.
    If vaRecipient = False Then Exit Sub 
     'Get the message from the user.
    Do 
        vaMsg = Application.InputBox( _ 
        Prompt:="Please enter the message such as:" & vbCrLf _ 
        & "Enclosed please find the weekly report.", _ 
        Title:="Message", Type:=2) 
    Loop While vaMsg = "" 
     
     'If the user has canceled the operation.
    If vaMsg = False Then Exit Sub 
     'Add the subject to the outgoing e-mail
     'which also can be retrieved from the users
     'in a similar way as above.
    Do 
        stSubject = Application.InputBox( _ 
        Prompt:="Please add a subject such as:" & vbCrLf _ 
        & "Weekly Report.", _ 
        Title:="Subject", Type:=2) 
    Loop While stSubject = "" 
     'Retrieve the path and filename of the active workbook.
    stAttachment = ActiveWorkbook.FullName 
     'Instantiate the Lotus Notes COM's Objects.
    Set noSession = CreateObject("Notes.NotesSession") 
    Set noDatabase = noSession.GETDATABASE("", "") 
     'If Lotus Notes is not open then open the mail-part of it.
    If noDatabase.IsOpen = False Then noDatabase.OPENMAIL 
     'Create the e-mail and the attachment.
    Set noDocument = noDatabase.CreateDocument 
    Set obAttachment = noDocument.CreateRichTextItem("stAttachment") 
    Set EmbedObject = obAttachment.EmbedObject(EMBED_ATTACHMENT, "", stAttachment) 
     'Add values to the created e-mail main properties.
    With noDocument 
        .Form = "Memo" 
        .SendTo = vaRecipient 
        .Subject = stSubject 
        .Body = vaMsg 
        .SaveMessageOnSend = True 
    End With 
     'Send the e-mail.
    With noDocument 
        .PostedDate = Now() 
        .Send 0, vaRecipient 
    End With 
     
     'Release objects from the memory.
    Set EmbedObject = Nothing 
    Set obAttachment = Nothing 
    Set noDocument = Nothing 
    Set noDatabase = Nothing 
    Set noSession = Nothing 
     
     'Activate Excel for the user.
    AppActivate "Microsoft Excel" 
    MsgBox "The e-mail has successfully been created and distributed.", vbInformation 
End Sub 
 
Postado : 29/06/2012 5:06 pm