?
Solved

Transfering Excel Content To Outlook Email Body

Posted on 2009-05-11
7
Medium Priority
?
388 Views
Last Modified: 2012-05-06
Hello Experts,

I'd like to set up a command buttion which when clicked will transfer all of the text in a range of cells in Excel (A1:I11) and place it in the body of an email in Outlook.

Please advise & thank you!
0
Comment
Question by:Escanaba
[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
  • 4
  • 3
7 Comments
 
LVL 59

Accepted Solution

by:
Saurabh Singh Teotia earned 1500 total points
ID: 24358648
There you go, I believe this is what you are looking for...
http://www.rondebruin.nl/mail/folder3/mail4.htm
further you can have a look over the following link:-
http://www.rondebruin.nl/sendmail.htm
which provides different ways to do what you want...
All credit Goes to genius Rondebruin.
Saurabh...
0
 
LVL 1

Author Comment

by:Escanaba
ID: 24358755
Thanks for the quick response Saurabh...
We are close but can you tell me what I need to do to prevent this from automatically sending the email out?  Ideally I want Outlook to open with the selected range in the body of the email and then have the end user put in their own send to, CC, BC and subject line information and then manually send it out.
0
 
LVL 1

Author Comment

by:Escanaba
ID: 24358770
Current Snippet:

Private Sub CommandButton1_Click() 
    Dim rng As Range
    Dim OutApp As Object
    Dim OutMail As Object 
    Set rng = Nothing
    On Error Resume Next
  Set rng = Sheets("Email Template").Range("A1:I11").SpecialCells(xlCellTypeVisible)
    On Error GoTo 0 
    If rng Is Nothing Then
        MsgBox "The selection is not a range or the sheet is protected" & _
               vbNewLine & "please correct and try again.", vbOKOnly
        Exit Sub
    End If 
    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With 
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0) 
    On Error Resume Next
    With OutMail
        .To = "Escanaba@whatever.com"
        .CC = ""
        .BCC = ""
        .Subject = "This is the Subject line"
        .HTMLBody = RangetoHTML(rng)
        .Send   'or use .Display
    End With
    On Error GoTo 0 
    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With 
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub
Function RangetoHTML(rng As Range)
' Changed by Ron de Bruin 28-Oct-2006
' Working in Office 2000-2007
    Dim fso As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook
 
    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
 
    'Copy the range and create a new workbook to past the data in
    rng.Copy
    Set TempWB = Workbooks.Add(1)
    With TempWB.Sheets(1)
        .Cells(1).PasteSpecial Paste:=8
        .Cells(1).PasteSpecial xlPasteValues, , False, False
        .Cells(1).PasteSpecial xlPasteFormats, , False, False
        .Cells(1).Select
        Application.CutCopyMode = False
        On Error Resume Next
        .DrawingObjects.Visible = True
        .DrawingObjects.Delete
        On Error GoTo 0
    End With
 
    'Publish the sheet to a htm file
    With TempWB.PublishObjects.Add( _
         SourceType:=xlSourceRange, _
         Filename:=TempFile, _
         Sheet:=TempWB.Sheets(1).Name, _
         Source:=TempWB.Sheets(1).UsedRange.Address, _
         HtmlType:=xlHtmlStatic)
        .Publish (True)
    End With
 
    'Read all data from the htm file into RangetoHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = ts.ReadAll
    ts.Close
    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
                          "align=left x:publishsource=")
 
    'Close TempWB
    TempWB.Close savechanges:=False
 
    'Delete the htm file we used in this function
    Kill TempFile
 
    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing
End Function 
  
  
 
  

Open in new window

0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 1

Author Comment

by:Escanaba
ID: 24358785
Ok...Nevermind....
Just realized the .display prompt which takes care of it.  Thanks so much for your assistance!!!
0
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 24359031
I was away for a while thats why wasnt able to reply you back and glad you were able to fix it, Also for my reference any particular reason why you graded it B..?
Saurabh...
0
 
LVL 1

Author Comment

by:Escanaba
ID: 24368643
Saurabh726
Your help was greatly appreciated.  I typically give a B grade when responses are links to another Q&A or publication rather than providing the code in the inital response.
 
0
 
LVL 59

Expert Comment

by:Saurabh Singh Teotia
ID: 24370232
Escanaba,
I agree that i gave you link to the page directly but isn't that page covered everything that you need, I can have copied the entire thing and pasted here and thats not the right thing since im not giving the credit to the right person who should ideally get it. Again my only point that i want to make out here, if you follow your rule which you mentioned you should ideally check how much re-work you need to do because of the link provided which was nothing in this case.
Saurabh...
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses

765 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