Dobut in sending mail thru VBA

gopdeep

Board Regular
Joined
Apr 24, 2012
Messages
94
pls have a luk on below code
Rich (BB code):
Private Sub CommandButton1_Click()
    Dim OutApp As Object
    Dim OutMail As Object
    Dim rng As Range
    Dim str As String, str1 As String
    Dim in1 As String, in2 As String
    in1 = InputBox("Range1:")
    in2 = InputBox("Range2:")
    Set rng = Sheets("sheet1").Range(in1 & ":" & in2).SpecialCells(xlCellTypeVisible)
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
    strbody = ActiveSheet.Range(in1 & ":" & in2).Select
    str = "<font face='Trebuchet MS' size=2 color=blue >" & "Hi All," & "<br><br>" & "Good Morning !!!" & "<br><br>" & "Please find today's allocation below:" & "<br><br>" & "</font>"
    str1 = "<font face='Trebuchet MS' size=2 color=blue >" & "Thanks," & "<br>" & "GopDeep" & "</font>"
    On Error Resume Next
        With OutMail
        .To = "gopdeep@aaa.com"
        .CC = "gopdeep1@aaa.com"
        .BCC = ""
        .Subject = "Sample" & Chr(32) & Range("H4") & " Mail it is"
        .HTMLBody = str & RangetoHTML(rng) & "<br><br>" & str1
        .Display
        .ReadReceiptRequested = True
    End With
    On Error GoTo 0
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

above code is working fine, but in mail body table is not appearing properly.

that is last row of the table is not having line in it... i couldn't resolve it even after many try... pls :help: me
 
This might work for you:

Private Sub CommandButton1_Click()

Dim OutApp As Object
Dim OutMail As Object
Dim rng As Range
Dim str As String, str1 As String
Dim in1 As String, in2 As String
in1 = InputBox("Range1:")
in2 = InputBox("Range2:")
Set rng = Sheets("sheet1").Range(in1 & ":" & in2).SpecialCells(xlCellTypeVisible)
Set OutApp = CreateObject("Outlook.Application")
OutApp.Session.Logon
Set OutMail = OutApp.CreateItem(0)
strbody = ActiveSheet.Range(in1 & ":" & in2).Select
str = "" & "Hi All," & "" & "Good Morning !!!" & "" & "Please find today's allocation below:" & "" & ""
str1 = "" & "Thanks," & "" & "GopDeep" & ""
On Error Resume Next
With OutMail
.To = "gopdeep@aaa.com"
.CC = "gopdeep1@aaa.com"
.BCC = ""
.Subject = "Sample" & Chr(32) & Range("H4") & " Mail it is"
.Body = str & (rng) & "" & str1
.Display
.ReadReceiptRequested = True
End With
On Error GoTo 0
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
 
Upvote 0
If not follow this as an example:

NOTE: the below script won't work unless has "all the necessary". But yo can use it as an example. This is what i use at work.

Sub Avocent_E() 'AVOCENT Electronice
Dim olLook As Object 'Start MS Outlook
Dim olNewEmail As Object 'New email in Outlook
Dim strEmailSubject As String 'Contact email address
Set olLook = CreateObject("Outlook.Application")
Set olNewEmail = olLook.CreateItem(0)
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Sheets("PARTURI SUSPECTE INCOMING").Select
ActiveWorkbook.Save
Subject = ActiveCell.Offset(0, 1).Range("A1")

nameList = nameList & ";" & Sheets("Emails").Range("C5").Value 'Contacts range
EmailSendTo = nameList
With olNewEmail 'Attach template
.To = EmailSendTo
.CC = Sheets("Emails").Range("C6").Value
.Body = strEmailText
.Subject = strEmailSubject
'.attachments.Add ("S:\Email template\Information Templatev3.xls")
.Display

End With
End Sub
 
Upvote 0
well it doesn't work...

example which you provided is to get the TO IDs from cells but i wants to get table from sheet which will be pasted in BODY of the mail.

my code is working as expected, but the problem is last row doesn't have line to enclose the table.

still if you need more details pls let me know the way to paste the screenshot in post, so that i can provide it.
 
Upvote 0
:confused: then...

i'll try to explain the issue pls resolve it...

am copying one table from the excel sheet and pasting it into the body of mail. in this case - last row of the table is not having line at bottom, table is getting pasted properly except last row. because bottom line is missing at the end of run.

can you correct it................................:eeek:
 
Upvote 0
here you should note that last line in the sense just LINE... data and all getting copied & pasted properly... pblm is only with drawing a line at bottom...
 
Upvote 0

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