[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Excel VBA - send the workbook you are in

Posted on 2011-03-16
4
Medium Priority
?
330 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:Murray Brown
[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 1000 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 1000 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:Murray Brown
ID: 35166662
thanks very much
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

649 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