слишком много копий / вставок) заполните данные и отправьте почту должно быть IN цикл: Sub send_email ()
Dim NewMail As Object
Dim MailConfig As Object
Dim SMTP_Config As Variant
Dim strSubject As String
Dim strFrom As String
Dim strTo As String
Dim strCc As String
Dim strBcc As String
Dim strsub As String
Dim strBody As String
Dim fields As Variant
Dim msConfigURL As String
Dim i As Long
strSubject = "Mail from Excel"
strFrom = "123@gmail.com"
For i = 1 To 50
strTo = Cells(i, 1).Value
strCc = ""
strBcc = ""
strsub = "123"
strBody = "Dear " & Cells(i, 1).Value & vbNewLine & vbNewLine & _
vbNewLine & vbNewLine & "we are ing this call to you : " & Cells(i, 1).Value & _
vbNewLine & vbNewLine & "Your total of this week is : " & Cells(i, 1).Value & _
vbNewLine & _
vbNewLine & _
vbNewLine & vbNewLine & "Thanks and Regards" & vbNewLine & _
vbNewLine & "Uedamoorthy CCSC" & vbNewLine & _
vbNewLine & "CCSC Che"
'Str (Sheet1.Cells(1, 1)) & Str(Sheet1.Cells(1, 2)) ---------------- wthat's this?
Set NewMail = CreateObject("CDO.Message")
Set MailConfig = CreateObject("CDO.Configuration")
MailConfig.Load -1
Set fields = MailConfig.fields
msConfigURL = "http://schemas.microsoft.com/cdo/configuration"
With fields
'Enable SSL Authentication
.Item(msConfigURL & "/smtpusessl") = True
'Make SMTP authentication Enabled=true (1)
.Item(msConfigURL & "/smtpauthenticate") = 1
'Set the SMTP server and port Details
'To get these details you can get on Settings Page of your Gmail Account
.Item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
.Item(msConfigURL & "/smtpserverport") = 465
.Item(msConfigURL & "/sendusing") = 2
'Set your credentials of your Gmail Account
.Item(msConfigURL & "/sendusername") = ""
.Item(msConfigURL & "/sendpassword") = ""
'Update the configuration fields
.Update
End With
NewMail.Configuration = MailConfig
NewMail.Subject = strSubject
NewMail.From = strFrom
NewMail.To = strTo
NewMail.TextBody = strBody
NewMail.CC = strCc
NewMail.BCC = strBcc
NewMail.Send
MsgBox ("Value has been Sent")
Exit_Err:
Set NewMail = Nothing
Set MailConfig = Nothing
End
Next
'------------------finish loop
End Sub
, но следующий немного лучше, чем для меня (то же самоекод, просто сгруппировать его):
Sub send_email()
Dim NewMail As Object
Dim MailConfig As Object
Dim SMTP_Config As Variant
Dim strSubject As String
Dim strFrom As String
Dim strTo As String
Dim strCc As String
Dim strBcc As String
Dim strsub As String
Dim strBody As String
Dim fields As Variant
Dim msConfigURL As String
Dim i As Long
strSubject = "Mail from Excel"
strFrom = "123@gmail.com"
strCc = ""
strBcc = ""
strsub = "123"
'Str (Sheet1.Cells(1, 1)) & Str(Sheet1.Cells(1, 2)) ---------------- wthat's this?
Set NewMail = CreateObject("CDO.Message")
Set MailConfig = CreateObject("CDO.Configuration")
MailConfig.Load -1
Set fields = MailConfig.fields
msConfigURL = "http://schemas.microsoft.com/cdo/configuration"
With fields
'Enable SSL Authentication
.Item(msConfigURL & "/smtpusessl") = True
'Make SMTP authentication Enabled=true (1)
.Item(msConfigURL & "/smtpauthenticate") = 1
'Set the SMTP server and port Details
'To get these details you can get on Settings Page of your Gmail Account
.Item(msConfigURL & "/smtpserver") = "smtp.gmail.com"
.Item(msConfigURL & "/smtpserverport") = 465
.Item(msConfigURL & "/sendusing") = 2
'Set your credentials of your Gmail Account
.Item(msConfigURL & "/sendusername") = ""
.Item(msConfigURL & "/sendpassword") = ""
'Update the configuration fields
.Update
End With
NewMail.Configuration = MailConfig
NewMail.Subject = strSubject
NewMail.From = strFrom
NewMail.CC = strCc
NewMail.BCC = strBcc
'--------------- start loop
For i = 1 To 50
strTo = Cells(i, 1).Value
strBody = "Dear " & Cells(i, 1).Value & vbNewLine & vbNewLine & _
vbNewLine & vbNewLine & "we are ing this call to you : " & Cells(i, 1).Value & _
vbNewLine & vbNewLine & "Your total of this week is : " & Cells(i, 1).Value & _
vbNewLine & _
vbNewLine & _
vbNewLine & vbNewLine & "Thanks and Regards" & vbNewLine & _
vbNewLine & "Uedamoorthy CCSC" & vbNewLine & _
vbNewLine & "CCSC Che"
NewMail.To = strTo
NewMail.TextBody = strBody
NewMail.Send
MsgBox ("Value has been Sent")
Exit_Err:
Set NewMail = Nothing
Set MailConfig = Nothing
End
Next
'------------------finish loop
End Sub