Opening an Outlook New Message Email from Excel

Posted on 2011-09-13
Last Modified: 2012-08-13
continuation from previous related question:

7. after doing point 6 from previous question, then open a new email message (outlook 2007)
8. add the attachment of this newly created Mastercard - sm spreadsheet to it
9. add to the body of the email message the below text:

Dear Nalleli,

Please see attached file for regular load request.

Please let me know you received this email.

Thank you.


10. insert into the subject line this text:

MC - smTODAY'S DATE (example: MC-smSept10-11)
Question by:JaseSt
  • 5
  • 4
LVL 29

Expert Comment

ID: 36531757
Hi JaseSt,
You have not specified the sender email
LVL 29

Accepted Solution

gowflow earned 500 total points
ID: 36531969
It seems it went faster than expected !!! (compensating on hte slow start :) )

1) Copy the below code to Module1 after any End Sub (SELECT ALL right click COPY and paste in module1 after any END SUB)

Sub SendEmail(fName As String)
Dim wb As Workbook
Dim ws As Worksheet

Dim SendTo As String
Dim OutlookApp As Object
Dim MItem As Object
Dim subject_ As String
Dim attach_ As String

Application.DisplayAlerts = False

'Create Outlook
Set OutlookApp = CreateObject("Outlook.Application")

'Fill in Subject Details'
subject_ = "MC-" & Format(Now, "Mmmd-yy")
attach_ = fName
SendTo = ""

'Create the Email
Set MItem = OutlookApp.CreateItem(0)
With MItem
  .To = SendTo
  .Subject = subject_
  .Attachments.Add (attach_)
  .Body = "Dear Nalleli," & Chr(10) & Chr(10) _
    & "Please see attached file for regular load request." & Chr(10) _
    & "PIC:99554Freedom" & Chr(10) & Chr(10) _
    & "Please let me know you received this email." & Chr(10) & Chr(10) _
    & "Thank you." & Chr(10) & Chr(10) _
    & "Michael" & Chr(10) _
    & "Sovereign Gold Card Support" & Chr(10) _
    & ""

  'Send the Email
End With

'Clear Resources
Set MItem = Nothing
Set OutlookApp = Nothing

Application.DisplayAlerts = True
End Sub

Open in new window

2) Doubleclick Module2 set the lower icon to view 1 sub at a time (left icon)
3) Display Sub PushToBook
4) Delete the whole Sub
5) Copy the below code and paste it in Module2 (SELECT ALL right click COPY and PASTE after any END SUB in module2)

Sub PushToBook()
Dim ws As Worksheet
Dim WSS As Worksheet
Dim NewWS As Worksheet
Dim MaxRow, I, J As Long
Dim NewWb As Workbook
Dim NewWorkB As String

If gstFolderPushToBook = "" Then
    MsgBox ("You need to select a destination folder to store the PushToBook files created. Please go to Sheet 'Main' and select a folder before proceeding further.")
    Exit Sub
    If MsgBox("This process will create a new workbook with today's date and load in it all records in sheet 'MC Consolidated' that beare today's date." & Chr(10) & Chr(10) _
        & "Are you ready to start this process ?", vbQuestion + vbYesNo, "Push To Book") = vbYes Then
        Set ws = ActiveSheet
        Set NewWb = Workbooks.Add
        Set NewWS = NewWb.Sheets("Sheet1")
        NewWS.Name = Format(Now, "mm-dd-yyyy")
        'Mastercard - smSept9-11.xls'
        NewWb.SaveAs Filename:=gstFolderPushToBook & "Mastercard - sm" & Format(Now, "Mmmd-yy") & ".xls", FileFormat:=xlExcel8
        NewWorkB = NewWb.Name
        J = 1
        MaxRow = ws.UsedRange.Rows.count
        ws.UsedRange.AutoFilter Field:=10, Criteria1:=">=" & Date, Operator:=xlAnd, Criteria2:="<=" & Date
        For I = 1 To MaxRow
            If ws.Range(I & ":" & I).EntireRow.Hidden = False Then
                ws.Range("A" & I & ":I" & I).copy NewWS.Cells(J, 1)
                J = J + 1
            End If
        Next I
        ws.AutoFilterMode = False
        processCC NewWS
        With NewWS.Columns("A:I")
           .HorizontalAlignment = xlCenter
        End With
        Application.DisplayAlerts = False
        For Each WSS In NewWb.Worksheets
            If WSS.Name <> NewWS.Name Then WSS.Delete
        Next WSS
        'Set NewWb = Nothing
        'Set NewWS = Nothing
        Application.DisplayAlerts = True
        MsgBox ("Workbook: '" & NewWorkB & "' has been created successfully")
        SendEmail NewWb.FullName
    End If
End If
End Sub

Open in new window

6) Save the workbook ONTO A NEW NAME !!!!
7) Exit the workbook
8) start the workbook and activate pushToBook command and check the results.

PS we can add the Sender email when provide it.
Pls let me know your comments.

Author Comment

ID: 36532257
I'll look it over, but before I do, the sender email address is:
LVL 29

Expert Comment

ID: 36534147
ok then pls replace this following Line in Sub SendEmail
1) goto VBA
2) doubleclick Module1 click on left icon to view 1 sub at a time
3) Display Sub SendEmail(fName As String)
4) Replace This Line (in the first couple lines of the Sub under 'Fill in Subject Details)
SendTo = ""
By this Line
SendTo = ""
5) Save the workbook and close it
6) Start it again and try it out.


Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.


Author Closing Comment

ID: 36536787
Beautiful! Worked like a charm!!!

I ran it before I saw your last comment. I will insert that into the code and try it again tomorrow am with the send to address.

Great work, gowflow! Thank you.

I have a few other things for this MasterCard workbook - fairly simple I believe - and then have a few others for my Visa workbook if interested.
LVL 29

Expert Comment

ID: 36536837
Shoot all the questions that you want. Pls post here any other issue you may need help with as cannot screen all questions beeing posted to find yours. I had similar issue with an other question where the guy said he would post a new question he never told me about it and I waited he cot it answered where it all started with my formula.

Author Comment

ID: 36540057
Great! Here's the next one. You've done something very similar with going through Outlook and retrieving data for 'individual' sheets. This question is for emails coming in from our resellers: the MCR and HMF Account pages:

Author Comment

ID: 36542627
Inserted the send to email address and it worked perfectly. Wow! Great work gowflow. Getting rid of the day after day repetitive actions certainly saves me a lot of time and reduced potential for human error.
Thanks again!
LVL 29

Expert Comment

ID: 36544961
Well that's what is 'good developpment' all about !! Am glad I am part of getting your daily work more organised and better handled.

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding second domain to Autodiscover - Exchange 2010 26 54
Excel copy picture into Outlook email 7 44
Outlook importing calendar entries 6 63
exchange, outlook 2 21
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Read this checklist to learn more about the 15 things you should never include in an email signature.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
CodeTwo Sync for iCloud ( automatically synchronizes your Outlook 2016, 2013, 2010 or 2007 folders with iCloud folders available via iCloud Control Panel. This lets you automatically sync them with…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now