Generate email from excel list

badsham77

New Member
Joined
May 4, 2011
Messages
10
Hi,

I'm working on this coding. It should generate email according to the list I provided in Excel. The code goes like this

Sub GEMail()

Dim myOlApp As New outlook.Application
Dim myItem As outlook.MailItem

Set myItem = myOlApp.CreateItem(olMailItem)
Set myrecipient = myItem.Recipients.Add(Worksheets("Sheet1").Range("B5"))
Set myrecipient = myItem.Recipients.Add(Worksheets("Sheet1").Range("C5"))
'B5 is the email i want to send to
'B6 is the email i want to cc to
myrecipient.Type = olCC
End Sub

How to command the VB to seek for the next range B6, C6, B7, C7 onwards?

TQ
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
...you can use a for... next cicle.
For example:
Code:
Sub GEMail()
   
    Dim myOlApp As New outlook.Application
    Dim myItem As outlook.MailItem
    
    Set myItem = myOlApp.CreateItem(olMailItem)

For r = 5 to 'put number row until where arrives your list
For c = 2 to 'put number column until where arrives your list

    Set myrecipient = myItem.Recipients.Add(Worksheets("Sheet1").Range("B5"))
    Set myrecipient = myItem.Recipients.Add(Worksheets("Sheet1").Range("C5"))
'B5 is the email i want to send to
'B6 is the email i want to cc to
    myrecipient.Type = olCC

Next c,r

   End Sub
 
Upvote 0
Excuse my mistake:
Code:
Sub GEMail()         
Dim myOlApp As New outlook.Application     
Dim myItem As outlook.MailItem          
Set myItem = myOlApp.CreateItem(olMailItem)  

For r = 5 to 'put number row until where arrives your list 
For c = 2 to 'put number column until where arrives your list   
   
Set myrecipient = myItem.Recipients.Add(Worksheets("Sheet1").Cells(r, c))     
Set myrecipient = myItem.Recipients.Add(Worksheets("Sheet1").Cells(r +1, c) 
'B5 is the email i want to send to
 'B6 is the email i want to cc to     
myrecipient.Type = olCC 

Next c,r     

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

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