Linking Outlook to Excel

I would like to send an email via Outlook by clicking on a button in a Excel spreadsheet. The mail would contain some of the values in the spreadsheet.

I think I know how to send with VBE an email given the server name but it does not go through Outlook.

Thanks,

Antonio



Answer this question

Linking Outlook to Excel

  • paulorlowski

    Hi Antonio,

    Here is a line i wrote, which send an email with the file attached to it.

    x = the address you want to send to

    y = the subject of the message

    application.dialogs(xlDialogSendMail).show(x),(y)

    i am trying to send the same exaclly without the attached file, but cant.

    do you know how

    Shay


  • Alan Rueckgauer

    From an earlier post, the following standalone console module works, but I cannot make it work as an Excel Macro, I guess I need to import the correct namespaces:

    Module Module1

    Sub Main()

    Dim theApp, theNameSpace, theMailItem, myAttachment, MessageBody, subject

    'create a new Outlook Application Object,

    'direct it to the proper NameSpace,

    'create a new Mail Item and set the attachments collection

    theApp = CreateObject("Outlook.Application")

    theNameSpace = theApp.GetNameSpace("MAPI")

    theMailItem = theApp.CreateItem(0)

    myAttachment = theMailItem.attachments

    MessageBody = "MessageBody"

    subject = "subject"

    'add recipients to MailItem

    theMailItem.Recipients.Add("ac@gmail.com")

    theMailItem.subject = subject

    theMailItem.Body = MessageBody

    myAttachment.Add("c:\test.txt", 1, 1, subject)

    theMailItem.Send()

    theNameSpace.Logoff()

    End Sub

    End Module


  • TheFatih

    Hye

    See my answer on your other post "VB code not working in Excel Macro "

    Kind Regards

    Fiftyfive



  • Linking Outlook to Excel