ISSUE: Outlook 自動化在 [Outlook Application].Recipients.Add ("Jon Grande") 失敗
錯誤資訊:
運行時錯誤 438:“物件不支持此屬性或方法。
MS 示例:
uj5u.com熱心網友回復:
首先,您需要使用mail物件而不是App能夠呼叫Recipients屬性:
With Mail
Set MailRecip = .Recipients.Add("Jon Grande")
**Set MailRecip = .Recipients.Add("Jon Grande")**
Set MailRecip = .Recipients.Add("Graham [email protected]")
MailRecip.Type = 1 'Designates the above is TO recipients
.Subject = "[email protected]"
.Body = "<a href='tel:19254511573'> To Call CaolePepe (925-451-1573)</a> "
If Not myRecipients.ResolveAll Then
Mail.Display
End If
.Send 'this sends the mail
End With
此外,無需遍歷Recipients代碼中的所有內容并檢查Resolve方法呼叫結果:
For Each MailRecip In .Recipients
If Not MailRecip.Resolve Then
Mail.Display
End If
Next
相反,您可以使用Recipients.ResolveAll方法嘗試根據通訊簿決議集合中的所有Recipient物件。Recipients
在如何:以編程方式填寫 Outlook 中的收件人、抄送和密件抄送欄位一文中了解更多資訊。
uj5u.com熱心網友回復:
您正在嘗試將收件人添加到Application物件,這沒有任何意義。試試下面的更新代碼。(在我的腦海中):
Call TestOutlookIsOpen 'AUTHOR: Ron Debruin> https://www.rondebruin.nl/win/s1/outlook/openclose.htm
Call GetAppExePath("msaccess.exe") 'AUTHOR: Daniel Pineault, CARDA Consultants Inc.
' IsAppRunning ("Outlook.Application") 'https://www.devhut.net/createobjectoutlook-application-does-not-work-now-what/
' GetAppExePath("firefox.exe") 'AUTHOR: Daniel Pineault, CARDA Consultants Inc.
' GetAppExePath ("outlook.exe") 'AUTHOR: Daniel Pineault, CARDA Consultants Inc.
Dim App As Object 'Outlook.Application
Dim Mail As Object 'Outlook.MailItem
Dim MailRecip As Object 'Outlook.Recipient
Const olMailItem = 0
Set App = CreateObject("Outlook.application")
Set Mail = App.CreateItem(0)
With Mail
Set MailRecip = .Recipients.Add("Jon Grande")
Set MailRecip = .Recipients.Add("Graham [email protected]")
MailRecip.Type = 1 'Designates the above is TO recipients
.Subject = "[email protected]"
.Body = "<a href='tel:19254511573'> To Call CaolePepe (925-451-1573)</a> "
For Each MailRecip In .Recipients
If Not MailRecip.Resolve Then
Mail.Display
End If
Next
.Send 'this sends the mail
End With
Set MailRecip = Nothing
Set Mail = Nothing
Set App = Nothing
uj5u.com熱心網友回復:
知道了!
Set App = CreateObject("Outlook.application")
Dim msgRecipient As String
msgRecipient = "****************@gmail.comt"
Dim oMail As Object
Set oMail = App.CreateItem(0)
Set MailRecip = oMail.Recipients.Add(msgRecipient)
With oMail
Set MailRecips = oMail.Recipients
MailRecip.Type = 1 'Designates the above is TO recipients
.Subject = Me.[Company]
.Body = "<a href='tel:1925***-****'> To Call(925-***-*****)</a> "
If Not MailRecips.ResolveAll Then
oMail.Display
End If
.Send
'MailRecip.send 'this sends the mail
End With
Set MailRecip = Nothing
Set oMail = Nothing
Set App = Nothing
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/488990.html
