这将自动向使用该程序的用户发送电子邮件,但我希望从相同的电子邮件地址发送电子邮件,无论谁使用它。
这是我的代码。你能帮我一下吗?Dim msgBody
Dim thresholdInfo
Dim receipAddress
'msgBody=""+vbNewLine
thresholdInfo="xxx :"+CStr(Threshold.StatValue)+vbNewLine+vbNewLine
receipAddress="xx"
cc="xx"
SendMail receipAddress,msgBody+thresholdInfo,"xxxxxx"
Sub SendMail(recipient,msg,subject)
Dim objOutlook
Dim objOutlookMsg
Set objOutlook = CreateObject( "Outlook.Application" )
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
objOutlookMsg.To = recipient
objOutlookMsg.Cc = cc
objOutlookMsg.Subject = subject
objOutlookMsg.Body = msg
objOutlookMsg.Importance = Low
objOutlookMsg.Send
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
您是否尝试先声明发送方:
Dim Sender As Outlook.AddressEntry
Sender.Address = "your@email.com"
最后包括在你的Sub SendMail(recipient,msg,subject)
:
objOutlookMsg.Sender = Sender
更多信息在这里:https://learn.microsoft.com/en-us/office/vba/api/outlook.mailitem.sender