Get a selected range as a table on to an email

cds9892745745

New Member
Joined
Sep 2, 2009
Messages
9
Hi there,
i was write a script on a stationary inventory sheet.
This file has a sheet where the user can fill in a request for stationary and
i have a sheet with the list of stationary in column A and quanlity required (no.) in column b
what i want is a script which can insert this array (column A and B) on to an email body

i have written the script which shoots the email, however want to add the above table to the body of the email.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try this code

Add - Microsoft Outlook in Refrences
Code:
Sub send_range_as_table()
'''''''''''''''''' tools -> refrence -> Microsoft outlook
Dim olApp As Outlook.Application
Dim olMail As MailItem
Dim mailbody As String
' <br> used to insert a line ( press enter)
' create a table using html
' check the link below to know more about html tables
' [url=http://www.w3schools.com/html/html_tables.asp]HTML Tables[/url]
' html color code
'http://www.computerhope.com/htmcolor.htm or [url=http://html-color-codes.info/]Html Color Codes[/url]
'bg color is used for background color
' font color is used for font color
'<b> bold the text [url=http://www.w3schools.com/html/html_formatting.asp]HTML Text Formatting[/url]
'   is used to give a single space between text
'<p style="font-size:15px">This is some text!</p> used to reduce for font size
' name and no is header
'********************* created header of table
mailbody = "<TABLE Border=""1"", Cellspacing=""0""><TR>" & _
"<TD Bgcolor=""#2B1B17"", Align=""Center""><Font Color=#FCDFFF><b><p style=""font-size:18px"">Name </p></Font></TD>" & _
"<TD Bgcolor=""#2B1B17"", Align=""Center""><Font Color=#FCDFFF><b><p style=""font-size:18px"">No </p></Font></TD>" & _
"</TR>"
For i = 2 To Sheets(1).Range("a65356").End(xlUp).Row
mailbody = mailbody & "<TR>" & _
"<TD ><center>" & Sheets(1).Range("a" & i).Value & "</TD>" & _
"<TD><center>" & Sheets(1).Range("b" & i).Value & "</TD>" & _
"</TR>"
Next i

' <br> used to insert a line ( press enter)
Set olApp = New Outlook.Application
Set olMail = olApp.CreateItem(olMailItem)
With olMail
.To = "[EMAIL="koul.ashish@gmail.com"]koul.ashish@gmail.com[/EMAIL]"
.CC = ""
.Subject = "Send Range in the body of outlook email as Formatted Table"
.HTMLBody = "Please find the ----- below ----- <br><br> " & mailbody & "</Table><br> <br>Regards <br> <br> Ashish Koul"
.Display
'.Send
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,771
Messages
6,126,799
Members
449,337
Latest member
BBV123

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