vba insert multiple ranges from excel to body of email - how???

Angie28

New Member
Joined
Mar 29, 2015
Messages
3
Hello, could you somebody help me with really hard vba code for me? Im beginner and I need to do replace an email with date ...and copy multiple ranges from excel to the body of reply email. Why my macro doesnt work? do you know it? thank you very much.... i tried RangetoHTML for first time, but it doesnt work..my excel doesnt work with it..

could you help me please?

Sub ReplyMail()
Dim olApp As Outlook.Application
Dim olNs As Namespace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim objMessage As Object
Dim i As Integer
Dim Rng As Range
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
i = 1
Set Rng = Range("A1:H3").value
On Error Resume Next
For Each olMail In Fldr.Items
If olMail.SenderEmailAddress = "xsedk1@gmail.com" Then
With olMail.Reply
.To = "test"
.CC = "test"
.Body = Hello. & Rng & Chr(10) & Chr (10) & "we agree with your portfolio here attached and according to it we see no move for today." & _
Chr (10) & " Best Regards." & _
Chr(10) & _
Chr(10) & Signature
.Display
End With
i = i + 1
End If
Next olMail
For Each objMessage In Fldr.Items
objMessage.UnRead = False
Next
End Sub

thak you very much for your help.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hi Angie,

first of all, if you post code, please put it between code tags (see example in red below). That way it is easier to read and it keeps its formatting.

secondly, where does your code fail?
do you know you can step through your code?
Instead of running the macro, place the cursor somewhere in the macro and then press F8 key to step through. It is then easier to see what is happening.

Further help on emailing sheets or parts of a sheet can be found in these resources:
Mail from Excel with Outlook (VBA) (very thorough, excellent resource)
Automate Outlook using vba: Sending Email from Excel using Outlook
VBA Code Snippet #23 - Create Email from Excel with File Attachment - Mr Spreadsheets

there are many more examples, but this should be enough.

You can see that you can set the body text to a range. You have to create the body text once. So if your bodytext consists of several parts of the sheet, you need to build it up before setting it.

A range can consist of more ranges itself, for instance : range("A1:G10,J2:L24")

hope this helps
 
Upvote 0

Forum statistics

Threads
1,216,381
Messages
6,130,294
Members
449,570
Latest member
TomMacca52

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top