我正在使用VBA通过点击按钮发送电子邮件 - 我的错误是电子邮件正文导致调试错误说:
对象'_Global失败
的方法'范围'
这是我的代码:
Dim CDO_Mail_Object As Object
Dim CDO_Config As Object
Dim SMTP_Config As Variant
Dim Email_Subject, Email_Send_From, Email_Send_To, Email_Cc, Email_Bcc, Email_Body As String
Email_Subject = "Yesterdays STE Figures"
Email_Send_From = ActiveSheet.Range("P1")
Email_Send_To = "123@test.com"
Email_Cc = ""
Email_Bcc = ""
Email_Body = Range("C5") & " " & Range("D5") & " " & Range("E5") & " " & Range("F5") & " " & Range("G5") & " " & Range("H5") & " " & Range("I5") & " " & Range("J5") & " " & Range("K5") & " " & Range("L5") & " " & Range("M5") & " " & Range("N5") & "<br>" & _
Range("C6") & " " & Range("65") & " " & Range("E6") & " " & Range("F6") & " " & Range("G6") & " " & Range("H6") & " " & Range("I6") & " " & Range("J6") & " " & Range("K6") & " " & Range("L6") & " " & Range("M6") & " " & Range("N6")
Set CDO_Mail_Object = CreateObject("CDO.Message")
On Error GoTo debugs
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
'please put your server name below
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailhost"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
.Update
End With
With CDO_Mail_Object
Set .Configuration = CDO_Config
End With
CDO_Mail_Object.Subject = Email_Subject
CDO_Mail_Object.From = Email_Send_From
CDO_Mail_Object.To = Email_Send_To
CDO_Mail_Object.TextBody = Email_Body
CDO_Mail_Object.CC = Email_Cc 'Use if needed
CDO_Mail_Object.BCC = Email_Bcc 'Use if needed
CDO_Mail_Object.AddAttachment FileToAttach 'Use if needed
CDO_Mail_Object.Send
debugs:
If Err.Description <> "" Then MsgBox Err.Description
MsgBox "Email Sent!", vbInformation
我认为我可以使用简单的范围公式简化它:
范围( “C5:N5”)
不幸的是,甚至无法让它工作。
感谢任何帮助