Solved

Excel VBA - send the workbook you are in

Posted on 2011-03-16
4
305 Views
Last Modified: 2012-08-14
Hi

What Excel VBA code will you use to send the workbook that you are in as an attachment
or in the body of the email seamlessly
0
Comment
Question by:murbro
  • 2
4 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 250 total points
ID: 35146823
IN teh following code NewOutlookMail is used to send an email using the outlook client.  sub saveme demonstrates a sequence to send a copy of the current file via the temp folder.

It displays the email for edit as currently presented, when happy replace the second line with

    NewOutlookMail "Subject orf email", "INtro Body Text", "name@domain.com", , , True, True, (Environ("temp") & "\" & ThisWorkbook.Name)

Which will send automatically

Chris
Sub saveme()

    ThisWorkbook.SaveCopyAs (Environ("temp") & "\" & ThisWorkbook.Name)
    NewOutlookMail "Subject orf email", "INtro Body Text", "name@domain.com", , , False, True, (Environ("temp") & "\" & ThisWorkbook.Name)
    Kill (Environ("temp") & "\" & ThisWorkbook.Name)
    
End Sub

Function NewOutlookMail(strSubject As String, strBody As String, Optional strTo As String, _
                            Optional strCC As String, Optional strBCC As String, Optional SendYN As Boolean = False, _
                            Optional AttachYN As Boolean = False, Optional Attach1 As String) As Boolean
Dim olkApp As Object

    Set olkApp = CreateObject("outlook.application")
    With olkApp.CreateItem(0)
        .To = strTo
'        .replyto = "fred@jdomain.com"
        If strCC <> "" Then .CC = strCC
        If strBCC <> "" Then .BCC = strBCC
        .Subject = strSubject
        .body = strBody
        If AttachYN And Attach1 <> "" Then .Attachments.Add Attach1
        If SendYN Then
            .Send
        Else
            .Display
        End If
    End With

End Function

Open in new window

0
 
LVL 85

Assisted Solution

by:Rory Archibald
Rory Archibald earned 250 total points
ID: 35146832
Activeworkbook.Sendmail "blah@yadda.com", "here's the workbook"

Open in new window


is the simplest way to send as an attachment.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 35146910
:o)

I do forget the simple!

Chris
0
 

Author Closing Comment

by:murbro
ID: 35166662
thanks very much
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

856 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