Solved

Excel VBA - send the workbook you are in

Posted on 2011-03-16
4
299 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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