Excel Macro send email

I have a report that I would like to send via excel. it will include recipients, subject and body information. in fact, he could copy the corresponding cells. what i have done so far, create a button and assign it a macro with this code:

Private Sub CommandButton1_Click()
 Application.Dialogs(xlDialogSendMail).Show arg1:=Sheets("Sheet1").Range("E3"), _
                      arg2:=Sheets("Sheet1").Range("E7")

End Sub

the problem is that this command sends the workbook as an attachment.

can someone help me with a code that will allow me to do this.

thanks a million!

amuses

+3
source share
2 answers

" Microsoft xx.x", , , :

. .display .send, .

Sub EmailFromExcel()
    On Error GoTo PROC_EXIT
    Dim OL As New Outlook.Application

    Dim olMail As Outlook.MailItem
    Set olMail = OL.CreateItem(olMailItem)

    Dim SrcSheet As Excel.Worksheet
    Set SrcSheet = Sheets("Sheet1")

    With olMail
        .To = SrcSheet.Range("E3").Text
        .Subject = SrcSheet.Range("E7").Text
        .Body = SrcSheet.Range("E12").Text
        .Display vbModal
        '.Send
    End With

 PROC_EXIT:
    On Error GoTo 0
    OL.Quit
    Set OL = Nothing
End Sub
+3

outlook com; / , , Outlook.

0

Source: https://habr.com/ru/post/1705122/


All Articles