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
 
As I said I can reproroduce your problem if the last row doesn't have a bottom border. Under Format Cells|Borders tab it may appear to have a bottom border when actually it doesn't. What you are seeing is the top border of the cell below. So delete the bottom border and close the dialog. Then open the dialog and add a bottom border. Then try your code.
 
Upvote 0
I get an error on this line:

Code:
Set rng = Sheets("Sheet1").Range(in1 & ":" & in2).SpecialCells(xlCellTypeVisible)
 
Upvote 0
Ooops... but its working fine to me... problem is only with the table format in mail... at beginning of this loop you too tried with the same code and informed me that code was working fine to you right,.. but now i couldn't understand that why it is throwing error at below code as you saying :confused:

Code:
Set rng = Sheets("Sheet1").Range(in1 & ":" & in2).SpecialCells(xlCellTypeVisible)

but still i can suggest below way to over come it.

Just remove the below code from "Sheet1" part-
Code:
gopi:    in2 = InputBox("Range2:")
    If in2 = "" Then
    resp = MsgBox("No entry detected. Do you want to try again?", vbCritical + vbYesNo, "INVALID ENTRY")
    If resp = vbYes Then
    GoTo gopi
    Else
    Exit Sub
    End If
    End If

instead of this pls use like
Code:
in2="i7"

i've verified it and found that it is working fine
 
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