2013-07-24 26 views
-2
Sub Mail_ActiveSheet() 
' Works in Excel 2000, Excel 2002, Excel 2003, Excel 2007, Excel 2010, Outlook 2000, Outlook 2002, Outlook 2003, Outlook 2007, Outlook 2010 
    Dim Sourcewb As Workbook 
    Dim Destwb As Workbook 
    Dim Cell As Range 
    Dim Subj As String 
    Dim EmailAddr As String 
    Dim cc As String 
    Dim bcc As String 
    Dim Body As String 
    Dim Attment As String 
    Dim OutApp As Object 
    Dim OutMail As Object 
    Dim X As String 

    X = Range("B2").Select 
    Do Until ActiveCell = "" 
    company = ActiveCell 
    ActiveCell.Offset(0, 1).Range("A1").Select 
    i = ActiveCell 
    ActiveCell.Offset(0, 2).Range("A1").Select 
    cemail = ActiveCell 
    ActiveCell.Offset(1, -3).Range("A1").Select 
    EmailAddr = Range("L2") 
    cc = Range("M2") 
    bcc = Range("N2") 
    Subj = Range("O2") 
    Attment = Range("P2") 
    Body = "Dear All," & vbLf _ 
    & vbLf _ 
    & "Request you to present the ECS as per the below details & Pl confirm after submission of the data file.  " & vbLf _ 
    & vbLf _ 
    & "CECS handover date                 :" & Range("I2") & vbLf _ 
    & vbLf _ 
    & "Settlement Date                    :" & Range("J2") & vbLf _ 
    & vbLf _ 
    & "Number of records                   :" & Range("F2") & vbLf _ 
    & vbLf _ 
    & "Total Contra Amount                 : " & Range("G2") & vbLf _ 
    & vbLf _ 
    & "Type of presentation                  : ECS Debit" & vbLf _ 
    & vbLf _ 
    & "Attachments                              : E-2 Form/Validation Reports/ECS data file" & vbLf _ 
    & vbLf _ 
    & "Thanks & Regards" & vbLf _ 
    & vbLf _ 
    & "GOBI L" & vbLf _ 
    & "ING VYSYA BANK LTD | CECS | 100, EDEN PARK | 20 VITTAL MALLYA ROAD | BANGALORE-560001 | PH :080-22532127 | " 

    With Application 
     .ScreenUpdating = False 
     .EnableEvents = False 
    End With 

    Set Sourcewb = ActiveWorkbook 
    Set Destwb = ActiveWorkbook 

    Set OutApp = CreateObject("Outlook.Application") 

    Set OutMail = OutApp.CreateItem(0) 

     With OutMail 
      .To = EmailAddr 
      .cc = cc 
      .bcc = bcc 
      .Subject = Subj 
      .Body = Body 
      .Attachments.Add (Attment) 
      .Display 
     End With 
     Loop 

    Set OutMail = Nothing 
    Set OutApp = Nothing 

    With Application 
     .ScreenUpdating = True 
     .EnableEvents = True 
    End With 

End Sub 
+1

你有什麼試圖解決你的問題?你的代碼在哪裏失敗?負責迭代表單的部分在哪裏?你是什​​麼意思*'我需要爲下面的表格添加循環,這樣我就可以發送很多郵件在單獨的單獨的單獨的郵件中的孤立* *?你很不清楚,你沒有表現出解決你的問題的任何努力。我們不只是爲你寫代碼,你在一個錯誤的地方好友。見[如何問](http://stackoverflow.com/questions/how-to-ask) – 2013-07-24 07:43:40

+0

你的問題是什麼?當你上次編輯你的帖子時,你提出了這個問題。 – PowerUser

回答

0

請仔細閱讀並遵守規則,並仔細閱讀所提供的鏈接。


至於你的問題,你嘗試過在列寫每個收件人,通過該表循環,然後發送郵件?

表可能看起來有點像這樣:

  A    B    C    
    +---------------+---------------+---------------+--- ... 
1 | [email protected] : [email protected] : [email protected] | 
2 | [email protected] : [email protected] : [email protected] | 
3 | [email protected] : [email protected] :    | 
    +---------------+---------------+---------------+--- ... 
4 | [email protected] :    :    | 
5 | [email protected] : [email protected] :    | 
6 |    :    :    | 
    +---------------+---------------+---------------+--- ... 

凡在第一線,你可以把收件人,在第二的CC和第三的嗜鉻細胞。在第四行中,它重新統計收件人。現在,您只需循環瀏覽表格併發送郵件。在側


小提示:你可以使用Step 3通過(而不是1)3的迭代之後的增加迭代器。