[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

Excel VBA - send the workbook you are in

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
Murray Brown
Asked:
Murray Brown
  • 2
2 Solutions
 
Chris BottomleyCommented:
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
 
Rory ArchibaldCommented:
Activeworkbook.Sendmail "blah@yadda.com", "here's the workbook"

Open in new window


is the simplest way to send as an attachment.
0
 
Chris BottomleyCommented:
:o)

I do forget the simple!

Chris
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks very much
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now