我已经阅读了多篇文章,并在microsoft论坛上进行了接触,但是还没有收到任何答案,只是更多问题。我不是一位经验丰富的编码员,主要只知道有关此问题的非常基本的信息。以下代码部分是我自己编写的,但其中大部分电子邮件部分已复制并粘贴。我正在尝试获取在脚本开头创建并关闭的工作簿,以作为附件上传到正在发送的电子邮件中。我已阻止引用我添加的附件上传部分。
Public Sub M_Emailer()
'creates the save file to send
Dim WBname As String
WBname = "BlackList" & ActiveSheet.Name & Format(Now(), "MMM dd, yyyy")
Workbooks.Add
ActiveWorkbook.SaveAs Filename:=WBname
Workbooks("blacklist system").Activate
Range("A1:F150").Select
Selection.Copy
Workbooks(WBname).Activate
Range("A1").Select
ActiveSheet.Paste
ActiveWorkbook.Save
ActiveWorkbook.Close
'sends email to Marik for blacklisted devices
Dim CDO_Mail As Object
Dim CDO_Config 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 strBody As String
将字符串暗淡为字符串
strSubject = "Blacklist From CDR"
strFrom = ""
strTo = ""
strCc = ""
strBcc = ""
strBody = WBname
strAtch =“ C:\ Users \ tabor \ Documents \”&WBname&“ .xlsx”
Set CDO_Mail = CreateObject("CDO.Message")
On Error GoTo Error_Handling
Set CDO_Config = CreateObject("CDO.Configuration")
CDO_Config.Load -1
Set SMTP_Config = CDO_Config.Fields
With SMTP_Config
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = ""
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Update
End With
With CDO_Mail
Set .Configuration = CDO_Config
End With
CDO_Mail.Subject = strSubject
CDO_Mail.From = strFrom
CDO_Mail.To = strTo
CDO_Mail.TextBody = strBody
CDO_Mail.Attachment = strAtch
CDO_Mail.CC = strCc
CDO_Mail.BCC = strBcc
CDO_Mail.Send
Error_Handling:
If Err.Description <> "" Then MsgBox Err.Description
End Sub