【发布时间】:2018-12-07 13:09:17
【问题描述】:
我的代理需要填写销售表格,然后再将其发送给另一个进行注册的代理。因此,当代理单击按钮时,我为按钮设置了脚本,它会向其他代理发送电子邮件,但 我不确定如何包含电子表格数据。
我该怎么做?
这是我一直在使用的代码:
Sub sendemail()
On Error GoTo Err
Dim NewMail As Object
Dim mailConfig As Object
Dim fields As Variant
Dim msConfigURL As String
Set NewMail = CreateObject("CDO.Message")
Set mailConfig = CreateObject("CDO.Configuration")
' load all default configurations
mailConfig.Load -1
Set fields = mailConfig.fields
'Set All Email Properties
With NewMail
.Subject = "Sales Follow up"
.From = ""
.To = ""
.CC = ""
.BCC = ""
End With
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.send
MsgBox ("Mail has been Sent")
Exit_Err:
Set NewMail = Nothing
Set mailConfig = Nothing
End
Err:
Select Case Err.Number
Case -2147220973 'Could be because of Internet Connection
MsgBox " Could be no Internet Connection !! -- " & Err.Description
Case -2147220975 'Incorrect credentials User ID or password
MsgBox "Incorrect Credentials !! -- " & Err.Description
Case Else 'Rest other errors
MsgBox "Error occured while sending the email !! -- " & Err.Description
End Select
Resume Exit_Err
End Sub
【问题讨论】:
-
我不明白这里发生了什么变化。我需要在电子邮件正文中发送活动工作表。这有点紧急。任何帮助都会很棒!提前谢谢你。
-
你试过
.AddAttachment吗? -
不,我没有。我不想将其添加为附件。 Juat 将工作表上显示的数据放入电子邮件中