473,804 Members | 3,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sending Range of Excel in Body of Email

2 New Member
I have finally worked out how to automatically send a range of cells in the body of an email using Outlook but it is very clumsy and I have to build up the email using the limit of line continuations. Is there any quicker and easier way of sending this email as it is always a set range of cells that I want to sent. At the moment my code looks like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub Email_DPV()
  3. Dim oFolder As Outlook.MAPIFolder
  4. Dim oItem As Outlook.MailItem
  5. Dim oOutlook As New Outlook.Application
  6. Dim MoOutlook As Outlook.Namespace
  7. Set MoOutlook = oOutlook.GetNamespace("MAPI")
  8. Set oFolder = MoOutlook.GetDefaultFolder(olFolderOutbox)
  9. Set oItem = oFolder.Items.Add(olMailItem)
  10. Sheets("Summary").Range("AE3").Font.Bold = True
  11. With oItem
  12.     .Recipients.Add ("iain.dykes@ocado.com")
  13.     .Subject = "Next Day AM/PM Balance"
  14.     .Body = Sheets("Summary").Range("AE3") & vbNewLine & _
  15.     Sheets("Summary").Range("AD4") & Sheets("Summary").Range("AE4") & vbNewLine & _
  16.     Sheets("Summary").Range("AD5") & "            " & Round(Sheets("Summary").Range("AE5"), 0) & vbNewLine & _
  17.     Sheets("Summary").Range("AD6") & "      " & Round(Sheets("Summary").Range("AE6"), 0) & vbNewLine & _
  18.     Sheets("Summary").Range("AD7") & "         " & Round(Sheets("Summary").Range("AE7"), 0) & vbNewLine & _
  19.     Sheets("Summary").Range("AD8") & "          " & Round(Sheets("Summary").Range("AE8"), 0) & vbNewLine & _
  20.     Sheets("Summary").Range("AD9") & "     " & Round(Sheets("Summary").Range("AE9"), 0) & vbNewLine & _
  21.     Sheets("Summary").Range("AD10") & "  " & Round(Sheets("Summary").Range("AE10"), 0) & vbNewLine & _
  22.     Sheets("Summary").Range("AD11") & "              " & Round(Sheets("Summary").Range("AE11"), 0) & vbNewLine & _
  23.     Sheets("Summary").Range("AD13") & Sheets("Summary").Range("AE13") & vbNewLine & _
  24.     Sheets("Summary").Range("AD14") & "          " & Round(Sheets("Summary").Range("AE14"), 0) & vbNewLine & _
  25.     Sheets("Summary").Range("AD15") & "     " & Round(Sheets("Summary").Range("AE15"), 0) & vbNewLine & _
  26.     Sheets("Summary").Range("AD16") & "        " & Round(Sheets("Summary").Range("AE16"), 0) & vbNewLine & _
  27.     Sheets("Summary").Range("AD17") & "         " & Round(Sheets("Summary").Range("AE17"), 0) & vbNewLine & _
  28.     Sheets("Summary").Range("AD18") & "    " & Round(Sheets("Summary").Range("AE18"), 0) & vbNewLine & _
  29.     Sheets("Summary").Range("AD19") & "  " & Round(Sheets("Summary").Range("AE19"), 0) & vbNewLine & _
  30.     Sheets("Summary").Range("AD20") & "              " & Round(Sheets("Summary").Range("AE20"), 0) & vbNewLine & _
  31.     Sheets("Summary").Range("AD22") & Sheets("Summary").Range("AE22") & vbNewLine & _
  32.     Sheets("Summary").Range("AD23") & "          " & Round(Sheets("Summary").Range("AE23"), 0) & vbNewLine & _
  33.     Sheets("Summary").Range("AD24") & "     " & Round(Sheets("Summary").Range("AE24"), 0) & vbNewLine & _
  34.     Sheets("Summary").Range("AD25") & "        " & Round(Sheets("Summary").Range("AE25"), 0) & vbNewLine & _
  35.     Sheets("Summary").Range("AD26") & "         " & Round(Sheets("Summary").Range("AE26"), 0) & vbNewLine & _
  36.     Sheets("Summary").Range("AD27") & "    " & Round(Sheets("Summary").Range("AE27"), 0) & vbNewLine & _
  37.     Sheets("Summary").Range("AD28") & "  " & Round(Sheets("Summary").Range("AE28"), 0) & vbNewLine & _
  38.     Sheets("Summary").Range("AD29") & "              " & Round(Sheets("Summary").Range("AE29"), 0)
  39.     .Importance = olImportanceNormal
  40.     .Send
  41. End With
  42. Set oItem = Nothing
  43. Set oFolder = Nothing
  44. End Sub
  45.  
If anyone has any suggestions then they would be very gratefully received.

Thanks.
Jul 21 '08 #1
0 1202

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5347
by: Niyazi | last post by:
Hi, I have to retrieve a data from AS400 DB2 and after working with data I have to export into one of existing Excel file. I can connect into specific library in AS400 DB2 using AS400 Client-Access v5.2 program using (in VB.NET) ODBC driver (DSN Name …) . I can retrieve datam work on it using VB.NET and I can send into 'NEW' Excel file. My first problem starts here:
10
26599
by: Maik | last post by:
Hello, I've got a problem with access to special ranges. I renamed some cells (for example "C4" in "CUSTOM.GENERAL.VPRIM"). This is necessary, because I have to read out only these cells in active worksheet. The method get_range("RangeName", Missing.Value) is ok as far as I have an existing RangeName. My program compares the root of a customized XML file with the range of an Excel file. But some root names don't exist in the Excel...
4
8468
by: IMS.Rushikesh | last post by:
Hi All, I am trying to execute below code but it gives me an COMException ///// Code Start //// public string GetName(Excel.Range range) { try { if (range.Name != null)
3
8903
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C Me.ListBoxPerson.Items.AddRange(ary)
2
1354
by: mkadasi | last post by:
Hello Everyone, I facing a problem in sending mail through vb.net. The code written below sends the mail to the respective person specified in the 'TO' address. But the problem is that the recipient recieves the mail in Spam. Can anybody help me out. Dim mail1 As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage mail1.From = "" mail1.To = ""
1
3647
by: rciiipo | last post by:
I have a question that is similar to a thread started by pauljhorak; however, my needs are a bit different / possibly more complicated. I have several files stored as outlook items (.msg). I would like to place keywords inside the .msg body section that I can replace with field values from my table. For example, name, greetings, etc. The to: field in the message will also come from field values. Also, I need to post a table into the...
0
1783
by: damimkader | last post by:
Hi, I'm trying to send emails using a Macro based on an Excel Sheet and the Email Client I'm using is Lotus Notes. OS used - Windows Xp. Language - VB Below is the Code I'm using for doing the same. Dim Maildb As Object
1
2881
by: the_ricka | last post by:
Hi all, I'm fairly new to python, but very excited about it's potential. I'm trying to write a simple program that will accept input from a command line and send email. The parameters I used on the command line are for From address, To addresses, Subject and Body. For the body, I thought it would be better to read the input from a file so I could allow someone to nicely format the body with newlines in a text editor and just read it...
1
1259
by: miketroy1 | last post by:
I would like to paste a range into the email body. VBA is not working well with that concept. Does the range need to convert to a string to be pasted into the body of email? How is that done? Thanks
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10327
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9161
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7625
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3828
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.