2015-10-20 27 views
0

您好我有我的所有客戶的電子郵件地址在我的Excel表A命名爲「電子郵件」。我創建了下面的代碼,當我在表單上按下底部時,彈出一個框,我可以輸入主題和幾個主體行。我希望能夠將相同的消息發送給我的所有客戶。 IE進行升級或如果我們不得不關閉辦公室等。任何人都可以幫忙嗎?如何VBA MAILto在一個列表中的所有電子郵件

Private Sub CommandButtonSend_Click() 


Dim Email_Subject, Email_Send_From, Email_Body1, Email_Body2, Email_Sig,   Email_Twitter As String 
Dim Mail_Object, Mail_Single As Variant 

Dim emailrange As Range, cell As Range 

Dim Email_Send_To As String 


Set emailrange = Worksheets("Email").Range("A2:A4") 

For Each cell In emailrange 
Email_Send_To = Email_Send_To & "j" & cell.Value 
Next 
Email_Send_To = Mid(Email_Send_To, 2) 
On Error Resume Next 

Email_Subject = UserFormTemplate.TextBoxSubject.Text 


Email_Send_From = "[email protected]" 


Email_Body1 = UserFormTemplate.TextBoxLine1.Text 
Email_Body2 = UserFormTemplate.TextBoxLine2.Text 

Email_Sig = UserFormTemplate.TextBoxSig.Text 

Email_Twitter = UserFormTemplate.TextBoxTwitter.Text 



On Error GoTo debugs 
Set Mail_Object = CreateObject("Outlook.Application") 
Set Mail_Single = Mail_Object.CreateItem(0) 
With Mail_Single 
.Subject = Email_Subject 
.To = Email_Send_To 
.cc = Email_Cc 
.BCC = Email_Bcc 
.Body = Email_Body1 & vbNewLine & Email_Body2 & vbNewLine & vbNewLine &  "Shaun Harrison Insurance Consultant" & vbNewLine & "Tel: 0800 308 1022/[email protected]" & vbNewLine & vbNewLine & Email_Twitter 
.send 
End With 
debugs: 
If Err.Description <> "" Then MsgBox Err.Description 
End 
End Sub 
+0

究竟是什麼在此代碼不能正常工作? –

回答

-2
Sub SendySend() 

With ActiveSheet 
    EndRow = .Cells(.Rows.Count, "A").End(xlUp).Row 
End With 

RowCount = 4 

For XCount = 4 To EndRow 

Dim olApp As Outlook.Application 
Set olApp = CreateObject("Outlook.application") 
Dim olmail As Outlook.MailItem 
Set olmail = olApp.CreateItem(olMailItem) 
    If Range("D" & RowCount).Value = "Yes" Then 
     olmail.To = Range("A" & RowCount).Value 
     olmail.Subject = Range("B" & RowCount).Value 
     olmail.Body = Range("C" & RowCount).Value 
     olmail.Send 
    Else 
     DontSend = 1 'This Doesn't do anything at all, it's just for clarity 
    End If 


RowCount = RowCount + 1 

Next 

End Sub 
+0

魔法'4'的含義是什麼? – xmojmr

+0

我低估了,因爲這是否真的* OP問題?它基本上與他編寫的代碼相同,只是他的個性化需求更加個性化,而且您的個性化方式適合您的需求,而且您沒有解釋可能相關或不相關的內容。它也沒有解釋早期和晚期綁定之間的區別,早期使用和晚期使用。 –

+0

公平評論,我認爲它可能有幫助,並且(正如您正確指出的那樣),我從以前的項目中獲得了舊代碼。 – Paul

相關問題