MrExcel Message Board

Go Back   MrExcel Message Board > Question Forums > Excel Questions

Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only.

Reply
 
Thread Tools Display Modes
Old Mar 1st, 2002, 02:27 AM   #1
angelrichardson
New Member
 
Join Date: Feb 2002
Location: Cleethorpes/UK
Posts: 2
Default

how do i do a mail merge- to e-mail addresses within excel? i would appreciate help! Cheers!

angelrichardson is offline   Reply With Quote
Old Mar 1st, 2002, 04:55 AM   #2
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

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
HTH,
D
dk is offline   Reply With Quote
Old Mar 1st, 2002, 08:00 AM   #3
Guest
 
Posts: n/a
Default

Quote:
On 2002-03-01 03:55, dk wrote:
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
HTH,
D
Can I change the Range ("A1:A5") trough an input box : Put in from ... to ...
(from to are the linenumbers)
Many thanks
  Reply With Quote
Old Mar 1st, 2002, 09:17 AM   #4
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

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
dk is offline   Reply With Quote
Old Mar 1st, 2002, 09:39 AM   #5
Guest
 
Posts: n/a
Default

Quote:
On 2002-03-01 08:17, dk wrote:
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", , , , , , [img]/board/images/smiles/icon_cool.gif[/img]

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
There must be an error in your macro on the line "Set rnge Adresses = Application ......
Can you give a solution please?
Many thanks
  Reply With Quote
Old Mar 1st, 2002, 09:46 AM   #6
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

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
dk is offline   Reply With Quote
Old Mar 1st, 2002, 10:16 AM   #7
Guest
 
Posts: n/a
Default

Quote:
On 2002-03-01 08:46, dk wrote:
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
This is the line now:Set rngeAddresses = Application.InputBox("Please select range containing e-mail addresses."),, "Select Range"
but is does not work.
What I do wrong?

  Reply With Quote
Old Mar 1st, 2002, 10:32 AM   #8
dk
MrExcel MVP
 
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
Default

Set rngeAddresses = Application.InputBox(prompt:="Please select range containing e-mail addresses.", Title:="Select Range", Type:=8)
dk is offline   Reply With Quote
Old Mar 1st, 2002, 10:34 AM   #9
Guest
 
Posts: n/a
Default

Quote:
On 2002-03-01 09:16, Anonymous wrote:
Quote:
On 2002-03-01 08:46, dk wrote:
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
This is the line now:Set rngeAddresses = Application.InputBox("Please select range containing e-mail addresses."),, "Select Range"
but is does not work.
What I do wrong?

Excuse me,I have found the error.
But the inputbox does not give me:
from ....... to .......
(I mean that I want to input the linenumbers because all my e-mail adresses are in colom A)So I like to input : 160 165 and then enter to send all to the e-mails who are in line 160 to 165
Can you change the macro?
  Reply With Quote
Old Mar 2nd, 2002, 04:11 AM   #10
Guest
 
Posts: n/a
Default

Quote:
On 2002-03-01 09:34, Anonymous wrote:
Quote:
On 2002-03-01 09:16, Anonymous wrote:
Quote:
On 2002-03-01 08:46, dk wrote:
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
This is the line now:Set rngeAddresses = Application.InputBox("Please select range containing e-mail addresses."),, "Select Range"
but is does not work.
What I do wrong?

Excuse me,I have found the error.

Still a little question about merge mail.
All my e-mail adresses are in sheet A
Text for body the e-mail is in sheet B
How can I merge this body to each mail adresses?
Have you a solution about that?
Many thanks
  Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT -4. The time now is 07:19 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
All contents Copyright 1998-2012 by MrExcel Consulting.
diabetic desserts recipes recipes Diabetic Soups Holiday Pizza Recipes Popcorn Recipes Recipes For Microwave Pasta Recipes Casserole Recipes Chili Recipes Curry Recipes Crockpot Recipes Apples Recipes Bread Recipes Vegetarian Recipes Vegetable recipes Desserts Recipes Appetizers Ethnic Recipes Meat Dishes Barbecue Recipes Sauces Recipes Marinade Recipes Low Fat Recipes Frugal Gourmet Kitchen Classics Recipes On The Grill Cook Books Seafood Recipes Cajun Recipes Breads Low Fat Low Fat Breads Bread Machine Recipes Yeast Breads Quick Breads Fat Free Vegetarian Salad Recipes Eggplant Recipes Radish Recipes Tomato Recipes Jalapeno Recipes Potato Recipes Lettuce Recipes Cabbage Recipes Beans Ambrosia Recipes Biscotti Recipes Desserts Low Fat Cookie Recipes Cheesecake Recipes Cake Recipes Pie Recipes Muffin Recipes Custard Recipes Best Appetizers Appetizers Low Fat Salsa Recipes Dip Recipes International Recipes Afghan Recipes Alaska Recipes French Recipes German Recipes Greek Recipes Italian Recipes Spanish Recipes Thai Recipes Korean Recipes Chinese Recipes Mexican Recipes Indian Recipes Beef Recipes Pork Pork & Ham Pork Butts Pork Chop Recipes Pork Ribs Rulled Pork Poultry Recipes Stews Recipes Ground Beef Barbecue Grill Barbecue Smoker All Purpose Sauce BBQ Sauce Barbecue Sauce Carolina BBQ Sauce Pickle Recipes Marinades Smoking Low Fat Appetizers & Dips Low Fat Breakfast Low Fat Cakes Low Fat Cheesecakes Low Fat Cookies Low Fat Desserts Low Fat Fish & Seafood Low Fat Meats Low Fat Pasta Low Fat Pies Low Fat Salads Low Fat Sandwiches Low Fat Sauces & Condiments Low Fat Sides Low Fat Soups Low Fat Vegetarian Baker's Dozen Taste of Home Recipe Book Bon Appetit Cookbook Blacktie Cookbook Buster Cook Book Cookbook USA Cook Book Cook Book Sara's Cookbook Sara's Cookbook Appetizers and Dips Poultry recipes Diabetic recipes Holiday recipes Miscellaneous recipes 110 recipes 1986 Usenet cookbook 2900 recipes Cyberrealm recipes Great sysops of world Specialty recipes Ceideburg recipes Cheese recipes Chili recipes Fruits recipes Garlic recipes Great chefs of NY Londontowne recipes Raisins recipes Recipes for kids US Food Vegetarian recipes Bread recipes Drinks Meat Dishes Brisket recipes Caribou recipes Chicken recipes Filet mignons recipes Pork recipes Swordfish recipes Turkey recipes Pasta recipes Uncategorized recipes Ethnic recipes Canada recipes English recipes Ethiopia recipes Germany recipes Greece recipes Mexican recipes Philippines recipes Welsh recipes Microwave recipes Soups recipes Vegetable recipes Asparagus recipes Barley recipes Brown rice recipes Lentil recipes Mushrooms recipes Salads recipes Wild rice Desserts recipes Cakes recipes Chocolate recipes Cookies recipes Ice cream recipes