Solved

Excel VBA - send the workbook you are in

Posted on 2011-03-16
4
313 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
[X]
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
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

688 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