how to send an email

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Rich (BB code):
sub Test()
select case  range("B2").value 
   case "qb"
      email2 "example@yahoo.com", "subject", "body"
   case "rs"
      email2 "example1@yahoo.com", "subject", "body"
end select
end sub

'-------
'YOU MUST ADD THE OUTLOOK APP IN REFERENCES!!!   checkmark OUTLOOK in the vbE menu, Tools, References
'-------
Public Function Email2(ByVal pvTo, ByVal pvSubj, ByVal pvBody) As Boolean
Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem
On Error GoTo ErrMail
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(olMailItem)
With oMail
    .To = pvTo
    .Subject = pvSubj
    .Body = pvBody
    .Attachments.Add activeworkbook.FullName, olByValue, 1
    
.Send
End With
EmailO = True
Set oMail = Nothing
Set oApp = Nothing
Exit Function
ErrMail:
MsgBox Err.Description, vbCritical, Err
Resume Next
End Function
 
Upvote 0
Thanks for you response. ok. i have the following vba codes :-

Sub Mail_ John1()

Range("b2") = Format(Date, "dd/mmmm/yyyy")

Const mydrive = "R:"

Const mydir = "Credit Admin\Seebaruth Rakesh\SEARCHES NO SIGNATURE"

Dim myname As String

Dim ss As String

myname = Sheets("sheet1").Range("e5").Text & Format(Date, "dd-mmm-yy") & ".xls"

ss = mydrive & "\" & mydir & "\" & myname & ".xls"

Application.DisplayAlerts = False

ActiveWorkbook.SaveCopyAs Filename:=ss

Application.DisplayAlerts = True

Dim i As Long, c As Range

For i = 1 To 2

Set c = Application.InputBox("Click in the cell to insert the Signature", Type:=8)

ActiveSheet.Pictures.Insert ("R:\Credit Admin\Seebaruth Rakesh\rakesh searches\sign.bmp")

With ActiveSheet.Shapes(ActiveSheet.Shapes.Count)

.LockAspectRatio = False

.Top = c.Top

.Left = c.Left

.Height = c.RowHeight

.Width = c.Width

End With

Next i

ActiveSheet.Protect "budget", True, True

Const mydrives = "R:"

Const mydirs = "Credit Admin\Seebaruth Rakesh\rakesh searches\2014"

Dim mynames As String

Dim ms As String

Dim OutApp As Object

Dim OutMail As Object

mynames = Sheets("sheet1").Range("e5").Text & Format(Date, "dd-mmm-yy") & ".xls"

ms = mydrives & "\" & mydirs & "\" & mynames & ".xls"

Application.DisplayAlerts = False

ActiveWorkbook.SaveCopyAs Filename:=ms

Application.DisplayAlerts = True

Set OutApp = CreateObject("Outlook.Application")

Set OutMail = OutApp.CreateItem(0)

On Error Resume Next

With OutMail

.To = "john@intnet.mu"

.CC = ""

.BCC = ""

.Subject = Range("e5")

.Attachments.Add ms

.Send

End With

On Error GoTo 0

Set OutMail = Nothing

Set OutApp = Nothing

ThisWorkbook.Saved = True

Application.Quit

End Sub

i have 12 Sub Mail from Sub Mail_ John1() to Sub Mail_ Peter12(). Each individuals have their respectives email addresses. i would like to club all these 12 sub mail(Sub Mail_ John1() to Sub Mail_ Peter12() ) into one single sub Mail. Let's assume that if cell E25=JOHN then email attachement to "john@intnet.mu" . If cell E25=PETER then email attachement to ''peter@intnet.mu'' and so on with the rest. Can you please amend my above vba codes with highlighted in bold. Your help would be much appreciated.

Regards

rakesh
 
Upvote 0

Forum statistics

Threads
1,222,310
Messages
6,165,258
Members
451,949
Latest member
bovacik

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