![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
New Member
Join Date: Feb 2002
Location: Cleethorpes/UK
Posts: 2
|
how do i do a mail merge- to e-mail addresses within excel? i would appreciate help! Cheers!
|
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Angel,
give this a go. You need to set a reference to the Microsoft Outlook Object Library (Tools, References in the VB editor) in order for this code to work. Code:
Sub EmailMerge()
Dim olApp As Outlook.Application, olMail As Outlook.MailItem
Dim rngeAddresses As Range, rngeCell As Range
Set olApp = New Outlook.Application
'Set this to where your addresses are
Set rngeAddresses = Sheets("Sheet1").Range("A1:A5")
For Each rngeCell In rngeAddresses.Cells
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = rngeCell.Value
olMail.Subject = "It's Friday"
olMail.Body = "The weekend is almost upon us - drink beer and be merry!"
olMail.Send
Next
End Sub
D |
|
|
|
|
|
#3 | |
|
Guest
Posts: n/a
|
Quote:
(from to are the linenumbers) Many thanks |
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Yep, change your code to that below. I've included some error handling code this time - just in case.
Regards, D Code:
Sub EmailMerge()
Dim olApp As Outlook.Application, olMail As Outlook.MailItem
Dim rngeAddresses As Range, rngeCell As Range
On Error GoTo ErrHandler
Set olApp = New Outlook.Application
Set rngeAddresses = Application.InputBox("Please select range containing e-mail addresses.", "Select Range", , , , , , :cool:
On Error Resume Next
If rngeAddresses Is Nothing Then Exit Sub 'User cancelled
On Error GoTo ErrHandler
For Each rngeCell In rngeAddresses.Cells
Set olMail = olApp.CreateItem(olMailItem)
olMail.To = rngeCell.Value
olMail.Subject = "It's Friday"
olMail.Body = "The weekend is almost upon us - drink beer and be merry!"
olMail.Send
Next
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation, "An error has occurred"
End Sub
|
|
|
|
|
|
#5 | |
|
Guest
Posts: n/a
|
Quote:
Can you give a solution please? Many thanks |
|
|
|
|
#6 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
The smiley shouldn't be there on that line. Replace all the crap (IMG SOURCE=blah blah) with the number 8 (that's eight just in case in gets screwed up again).
D |
|
|
|
|
|
#7 | |
|
Guest
Posts: n/a
|
Quote:
but is does not work. What I do wrong? |
|
|
|
|
#8 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
Set rngeAddresses = Application.InputBox(prompt:="Please select range containing e-mail addresses.", Title:="Select Range", Type:=8)
|
|
|
|
|
|
#9 | ||
|
Guest
Posts: n/a
|
Quote:
|
||
|
|
|
#10 | |||
|
Guest
Posts: n/a
|
Quote:
|
|||
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|