Let me start by saying that I am in NO WAY a programmer, and that I'm trying to learn as I go.
I'm trying to piece together some VB to send emails in Excel with CDO / SMTP.
The general Idea is:
1. Populate data throughout the day
2. At the end of shift, Press email button
3. Look at Table1 (F-O) and copy only the rows of data that have data in column F
4. Copy data to the body of the email and send it.
Here is what I have so far:
I know what I have is wrong/horrible to look at, but I'm still learning.
No matter what I try, I can't seem to get it to work.
Please help me.
Reegs
I'm trying to piece together some VB to send emails in Excel with CDO / SMTP.
The general Idea is:
1. Populate data throughout the day
2. At the end of shift, Press email button
3. Look at Table1 (F-O) and copy only the rows of data that have data in column F
4. Copy data to the body of the email and send it.
Here is what I have so far:
Code:
Sub SendEmailUsingSMTP()
Dim NewMail As CDO.Message
Dim strbody As String
Dim rng As Range
Set NewMail = New CDO.Message
'Enable SSL Authentication
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
'Make SMTP authentication Enabled=true (1)
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Set the SMTP server and port Details
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "MY_SERVER.com"
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Set your credentials of your Account
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MY_ADDRESS@WORK.com"
NewMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "MY_PW"
'Update the configuration fields
NewMail.Configuration.Fields.Update
'Set All Email Properties
'Select only used cells
Range("F1:O100").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="<>"
Columns("F:O").Select
Set rng = Selection
With rng
srtbody = rng
Range("F1").Activate
Selection.AutoFilter
Range("F2").Select
End With
With NewMail
.Subject = "EOS Scrap Log"
.From = "MY_ADDRESS@WORK.com"
.To = "SOME_PEOPLE@WORK.com"
.CC = ""
.BCC = ""
.TextBody = strbody
NewMail.Send
MsgBox ("Mail has been Sent")
'Set the NewMail Variable to Nothing
Set NewMail = Nothing
End With
End Sub
I know what I have is wrong/horrible to look at, but I'm still learning.
No matter what I try, I can't seem to get it to work.
Please help me.
Reegs
Last edited: