Click here to Skip to main content
15,909,737 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have 150 contacts in my table, I need to Mail an attachments to all of them at a time for that reason i would like to add all of them in BCC dynamically.

This is My code

Private Sub Send_Click()

Dim dbsheet As Worksheet

Set dbsheet = ThisWorkbook.Sheets("get")
lr = dbsheet.Cells(Rows.Count, 1).End(xlUp).Row

SelRow = Selection.Row
 
BatchId = dbsheet.Cells(SelRow, 1)

'Declare variables'
        
        Set objMyConn = New ADODB.Connection
        Set objMyRecordset = New ADODB.Recordset
        Dim strSQL As String

    'Open Connection'
        objMyConn.ConnectionString = "Provider=SQLOLEDB;Data Source=abc;Initial Catalog=abc;User ID=sa;Password=abc;"
        objMyConn.Open

    'Set and Excecute SQL Command'
        strSQL = "select EMail_1 from Student_Info where Branch_Code='ap' and Student_ID in ( select Student_ID from Admissions where Branch_Code='ap' and Batch_ID=BatchId)"

    
    Dim olApp As Outlook.Application
    Set olApp = CreateObject("Outlook.Application")
    
     
    Dim olMail As Outlook.MailItem
    Set olMail = CreateItem(olMailItem)
    
    olMail.To = "My MailID@gmail.com" 
    
 ' Here I'm facing Problem how to attach mails to BCC
    for
    
    olMail.BCC = ""
    

    olMail.Subject = "Subject Line"
    olMail.Body = "This is test Mail"
    olMail.Send
    
End Sub


I'm Using Excel 2010 VBA

anybody help me.......
Posted
Updated 6-Sep-13 15:51pm
v4

1 solution

this will do the work

loop arround

olMail.BCC.Add(New MailAddress("email@addes.com"));
 
Share this answer
 
Comments
Venkat Kumar chigulla 12-Sep-13 3:12am    
Depending on the Query my Mail Id's will be changed, could you tell me those 3 lines of code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900