tradeaccepted
New Member
- Joined
- Jun 11, 2013
- Messages
- 33
Hello,
I edited Ron DeBruins Excel VBA to Outlook email code below. Original code: (http://www.rondebruin.nl/win/s1/outlook/bmail2.htm)
My Excel sheet has Email Addresses listed in Column C.
The code runs successfully, but it changes the To value inside one newly opened email message. What I'm looking for is, if I have 10 email addresses in column C, how could I change my code to have Outlook open 10 separate new message windows.
I edited Ron DeBruins Excel VBA to Outlook email code below. Original code: (http://www.rondebruin.nl/win/s1/outlook/bmail2.htm)
My Excel sheet has Email Addresses listed in Column C.
The code runs successfully, but it changes the To value inside one newly opened email message. What I'm looking for is, if I have 10 email addresses in column C, how could I change my code to have Outlook open 10 separate new message windows.
Code:
Sub Mail_Selection_Range_Outlook_Body()'For Tips see: http://www.rondebruin.nl/win/winmail/Outlook/tips.htm
'Don't forget to copy the function RangetoHTML in the module.
'Working in Excel 2000-2016
Dim Rng As Range
Dim OutApp As Object
Dim OutMail As Object
Dim strbody As String
Dim SigString As String
Dim Signature As String
Dim lastRow As Long
Dim Rng1 As Range
'Find the last email address in column C.
lastRow = Range("C:C").Find("*", Range("C1"), Searchdirection:=xlPrevious).Row
Set Rng1 = Range(Cells(2, "C"), Cells(lastRow, "C"))
'Add signature to the email body
SigString = Environ("appdata") & _
"\Microsoft\Signatures\New.htm"
If Dir(SigString) <> "" Then
Signature = GetBoiler(SigString)
Else
Signature = ""
End If
'Signaute code end
'Start selection script
Set Rng = Nothing
On Error Resume Next
'Only the visible cells in the selection
'Set Rng = Selection.SpecialCells(xlCellTypeVisible)
'You can also use a fixed range if you want
Set Rng = Sheets("Credentials").Range("K2:L7").SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
'Loop though the emails in Column C
For Each cel In Rng1
On Error Resume Next
With OutMail
.To = cel.Value
.CC = ""
.BCC = ""
.Subject = ""
.HTMLBody = RangetoHTML(Rng)
.Display 'or use .Send
End With
On Error GoTo 0
Next cel
Set OutMail = Nothing
Set OutApp = Nothing
End Sub