我想發送電子郵件(包含主題,正文...)到另一個電子郵件地址。 我嘗試下面的代碼,但沒有奏效:使用PowerPoint VBA發送電子郵件
Private Sub CommandButton1_Click()
Dim ret As Boolean
Dim strAddress As String
Dim strMessage As String
strAddress = "[email protected]"
ret = SendEMail(strAddress, (Label1.Caption), strMessage)
Label1.Caption = ret
If Label1.Caption = "True" Then
MsgBox "Mail sent!"
ElseIf Label1.Caption = "False" Then
MsgBox "Mail not sent!"
End If
End Sub
Public Function SendEMail(strRecipient As String, strSubject As String, strBody As String) As Boolean
Dim oApp As Object
Dim oMail As Object
Err.Clear
On Error Resume Next
Set oApp = GetObject(Class:="Outlook.Application")
If Err <> 0 Then Set oApp = CreateObject("Outlook.Application")
Err.Clear
Set oMail = oApp.CreateItem(0)
With oMail
.Subject = strSubject
.To = strRecipient
'copy to self
.CC = "[email protected]"
.BodyFormat = 1
.Body = strBody
.Send
End With
'cleanup
Set oMail = Nothing
Set oApp = Nothing
'All OK?
If Err = 0 Then SendEMail = True Else SendEMail = False
End Function
代碼最初是從here拍攝。
如果可能,我想要一個與大多數PC兼容的代碼。
我嘗試了現在的另一個代碼... 但我得到一個錯誤:運行 - yime錯誤'-2147220978(8004020e)' 而且它還說,發件人的地址被拒絕。 –
如果您希望獲得任何幫助,您應該準確指定您嘗試過的其他代碼。理想情況下,您會將其添加到您的原始問題。 –
我嘗試過這裏的代碼,但是ir太長了。這是第一個大代碼[https://www.rondebruin.nl/win/s1/cdo.htm]。 –