2016-12-21 32 views
2

複数の人に送信する1つのメールを作成しようとしています。 今、私は1つの列に電子メールアドレスがあり、右側に「送信先」、「CC」または「BCC」のチェックボックスがあります。複数のTo、CC、BCCのメールをExcel VBAで作成

Emails address: B3 - B13 (this list will expand, i may end up using lastrow) 

"True/False" To: D3- D13 

"True/False" CC: F3- F13 

"True/False" BCC: H3- H13 

Send if TRUE, skip if FALSE. 

私は、これはすでに簡単な&程度であると確信しているが、私は見ていると私はこだわっています。すべての返信用

感謝。ここで

+2

何を試しましたか? –

+2

コードの一部が機能していませんか?もしそうなら、あなたのコードを質問に貼り付けて、どこに問題があるのか​​を教えてください。しかし、あなたの問題が何かについての手がかりがなくても、私たちが助けになる答えを推測することは非常に少ない**可能性があります。 – YowE3K

+2

あなたが試したことを示すことに加えて、*どのようにメールを送信しようとしていますか? Outlookで? Gmail?ホットメール? Yahoo? Lotus Notes? ... [お問い合わせ方法](https://stackoverflow.com/help/how-to-ask)をご覧ください。 – BruceWayne

答えて

1

は、説明のためのコメントを参照してください...もちろん質問はかなり曖昧だったので、特定のニーズに合わせてそれを適応させる、あなたが望む何をすべきマクロです。

Sub sendEmail() 

' Set up outlook objects for emailing 

Set OutApp = CreateObject("Outlook.Application") 
Set OutMail = OutApp.CreateItem(0) 

' Body text for the email 
Dim strbody As String 
strbody = "This text in the body of your email" 

' Strings to contain the email addresses 
Dim sendTo As String 
sendTo = "" 
Dim sendCC As String 
sendCC = "" 
Dim sendBCC As String 
sendBCC = "" 

' The cell containing the email address (loop variable) 
Dim emailCell As Range 

With ActiveSheet 

    ' Cycle through email addresses, from B3 to one before next blank cell in column 
    For Each emailCell In .Range("B3", .Range("B3").End(xlDown)) 

     ' Check each TRUE/FALSE column in same row, add email addresses accordingly 

     If .Cells(emailCell.Row, "D").Text = "TRUE" Then 

      sendTo = sendTo & "; " & emailCell.Text 

     End If 

     If .Cells(emailCell.Row, "F").Text = "TRUE" Then 

      sendCC = sendCC & "; " & emailCell.Text 

     End If 

     If .Cells(emailCell.Row, "H").Text = "TRUE" Then 

      sendBCC = sendBCC & "; " & emailCell.Text 

     End If 

    Next emailCell 

End With 

' Generate email in outlook objects defined above 
On Error Resume Next 
With OutMail 
    .To = sendTo 
    .CC = sendCC 
    .BCC = sendBCC 
    .Subject = "Subject Message Here" 
    .HTMLBody = strbody 
    .Display 
    ' If you don't want to display the email before sending it, 
    ' simply use .Send instead of .Display 
End With 
On Error GoTo 0 

End Sub 
関連する問題