Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Excel sending an email

Posted on 2016-10-10
5
78 Views
Last Modified: 2016-10-15
I need to be able to send an email via excel using the contents of a worksheet to populate the email. Then I need to be able to select the outlook mailbox which I wish to send the email from which won't be the default for outlook.
0
Comment
Question by:Sam Coombes
  • 2
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
yo_bee earned 500 total points
ID: 41837714
Here is a module that I use in my weekly reports that need to be e-mailed to all upper management.

Sub Email_Report(ByVal Fname As String)
    'sourced from:Automation of out look Mails based on the excel list
    'http://www.thecodecage.com/forumz/1054996151-post10.html
    'http://www.thecodecage.com/forumz/microsoft-outlook-forum/213688-search-new-email-text-make-bold-blue.html#post1055005238
    'RB: other constants to allow Late Binding*
    'Const olFolderInBox As Long = 6
    Dim OutApp As Object
    Dim oNameSpace As Object
    Dim OutMail As Object

'...other code & then...

    'check for open Outlook session & open if necessary
    'sourced from: Microsoft Office Help - Microsoft Office Discussion - Excel VBA Programming - Access Programming
    On Error Resume Next
    Set OutApp = GetObject(, "Outlook.Application")
    On Error GoTo 0

    '### may need modification
    If OutApp Is Nothing Then
        Set OutApp = CreateObject("Outlook.Application")
        Set oNameSpace = OutApp.GetNamespace("MAPI")
        oNameSpace.Logon , , True
        oNameSpace.GetDefaultFolder(olFolderInBox).Display
        'WasOutlookOpenedByCode = True
    End If

    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)

'Dim OutApp As Object
'Dim OutMail As Object
'Set OutApp = CreateObject("Outlook.Application")
'Set OutMail = OutApp.CreateItem(0)

'    On Error Resume Next
'   ' Change the mail address and subject in the macro before you run it.
   With OutMail
        .SentOnBehalfOfName = "PGA Tour"
        .To = "Mickelson, Phil; Woods,Tiger"
        .CC = "Fowler, Rickie"
        .BCC = "Nicklaus, Jack" '
        .Subject = "Golf Weekly Update"
        .Body = "Blah, Blah Blah"
        .Attachments.Add (Fname)
        .Sensitivity = 2


        ' You can add other files by uncommenting the following line.
        '.Attachments.Add ("C:\test.txt")
        ' In place of the following statement, you can use ".Display" to
        ' display the mail.
        .Send
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

ActiveWorkbook.Close savechanges:=True
'Excel.Application.Quit
'Outlook.Application.Quit
End Sub

Open in new window


What content are you looking to send?
Can you attach your Excel worksheet you are working with?
1
 

Author Comment

by:Sam Coombes
ID: 41837719
Thank you so much. I just need to send a couple of the cells of information. Which part of your code specifies which mailbox to use. As my outlook has 3 different email accounts and I need to select an account which email should be sent from.
0
 
LVL 1

Expert Comment

by:Andrew White
ID: 41837907
See Ron De Bruin's explanation of SendUsingAccount at http://www.rondebruin.nl/win/s1/outlook/account.htm
0
 
LVL 22

Expert Comment

by:yo_bee
ID: 41840092
Can you attach a sample of your excel worksheet so I can rework the code to meet your needs?
0
 

Author Closing Comment

by:Sam Coombes
ID: 41844724
I don't need the attachment bit but I will work on changing that thank u very much.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question