Mahantesh_Torgal
New Member
- Joined
- Sep 12, 2016
- Messages
- 25
Hi Excel Teachers,
Can you please please help me with this?
I have VBA listbox which populates data for a given specific date range.
But i want to send as an email this Listbox items in table format using SMTP technique.
I tried but not getting the exact way.
Could you please help!! Below is the sample code
----------------------------------------------------
Private Sub CommandButton2_Click()
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant, i As Integer
Dim strbody As String, tlr As Integer, rng As Range, mess As Range
'rng = ""
tlr = ThisWorkbook.Sheets("temp").Range("A" & Rows.Count).End(xlUp).Row
'Range("A2:G26").Select
'Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
'Range("A2").Select
'------mailing Listitems
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP.pfsweb.com"
.item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
strbody = "Hello All, " & vbNewLine & vbNewLine & _
"Below are the details of recovered Items : "
For i = 0 To UserForm20.ListBox1.ListCount - 1
With iMsg
Set .Configuration = iConf
'UserForm20.ListBox1.Selected(i) = True
.To = "mtoragall@pfsweb.com"
'.CC = ""
'.BCC = ""
.From = "easyasset@pfsweb.com"
.Subject = "EasyAsset Recovered Assets"
.Textbody = mess
'.Textbody = strbody & vbNewLine & vbNewLine & UserForm20.ListBox1.Column(1) & ", " & UserForm20.ListBox1.Column(2) & ", " & UserForm20.ListBox1.Column(3) & ", " & UserForm20.ListBox1.Column(4)
'Application.SendKeys "%s"
iMsg.Send
End With
Next i
End Sub
----------------------------------------------------
Regards,
Mahantesh
Can you please please help me with this?
I have VBA listbox which populates data for a given specific date range.
But i want to send as an email this Listbox items in table format using SMTP technique.
I tried but not getting the exact way.
Could you please help!! Below is the sample code
----------------------------------------------------
Private Sub CommandButton2_Click()
Dim iMsg As Object
Dim iConf As Object
Dim Flds As Variant, i As Integer
Dim strbody As String, tlr As Integer, rng As Range, mess As Range
'rng = ""
tlr = ThisWorkbook.Sheets("temp").Range("A" & Rows.Count).End(xlUp).Row
'Range("A2:G26").Select
'Selection.CopyPicture Appearance:=xlScreen, Format:=xlBitmap
'Range("A2").Select
'------mailing Listitems
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP.pfsweb.com"
.item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
strbody = "Hello All, " & vbNewLine & vbNewLine & _
"Below are the details of recovered Items : "
For i = 0 To UserForm20.ListBox1.ListCount - 1
With iMsg
Set .Configuration = iConf
'UserForm20.ListBox1.Selected(i) = True
.To = "mtoragall@pfsweb.com"
'.CC = ""
'.BCC = ""
.From = "easyasset@pfsweb.com"
.Subject = "EasyAsset Recovered Assets"
.Textbody = mess
'.Textbody = strbody & vbNewLine & vbNewLine & UserForm20.ListBox1.Column(1) & ", " & UserForm20.ListBox1.Column(2) & ", " & UserForm20.ListBox1.Column(3) & ", " & UserForm20.ListBox1.Column(4)
'Application.SendKeys "%s"
iMsg.Send
End With
Next i
End Sub
----------------------------------------------------
Regards,
Mahantesh