2017-09-05 346 views
0

我有我的代碼是這樣的:Outlook VBA。實施.SentOnBehalfOfName到我的代碼

Public WithEvents myItem As Outlook.MailItem 

Private Sub Application_ItemLoad(ByVal Item As Object) 
If Item.Class = olMail Then 
    Set myItem = Item 
End If 
End Sub 


Private Sub myItem_Open(Cancel As Boolean) 

Dim oAccount As Outlook.Explorer 
Dim oMail As MailItem 

Dim Recip As Outlook.Recipient 

Set oAccount = Application.ActiveExplorer 
MsgBox (oAccount.CurrentFolder.Store) 

If oAccount.CurrentFolder.Store = "[email protected]" Then 
MsgBox ("CC needs to be added") 


Set Recip = myItem.Recipients.Add("[email protected]") 
Recip.Type = olCC 
Recip.Resolve 


Else 
MsgBox ("no need to add CC") 
End If 
End Sub 

我想補充像myItem.SentOnBehalfOfName =「[email protected]」到我的代碼,而只是將其粘貼到我的代碼不起作用。我是編碼技術人員,所以可能我必須先設置一些東西。任何人都可以幫助我這個?

我一直在尋找幾個小時。我已經嘗試了myItem.SentOnBehalfOfName =「[email protected]」,但它實際上什麼都不做。它也沒有顯示任何錯誤,所以我不知道什麼可能是錯的。任何人都有線索?

+0

先搜索。基於該搜索,將myItem.SentOnBehalfOfName =「[email protected]」放入您的代碼中,如果有問題,則詢問有關問題。 – niton

+0

我一直在尋找幾個小時。我已經嘗試了myItem.SentOnBehalfOfName =「[email protected]」,但它實際上什麼都不做。它也沒有顯示任何錯誤,所以我不知道什麼可能是錯的。任何人都有線索? – Art

回答

0

這個棘手的SentOnBehalfOfName行爲在前面的文章中有描述。

Private Sub myItem_Open_SentonBehalf_Test() 

Dim oExpl As Explorer 
Dim myItem As mailitem 

Set oExpl = ActiveExplorer 
Set myItem = CreateItem(olMailItem) 
' Do not display 

If oExpl.CurrentFolder.store = "[email protected]" Then 

    Debug.Print "myItem.SentOnBehalfOfName:" & "x " & myItem.SentOnBehalfOfName & " x" 
    myItem.SentOnBehalfOfName = "[email protected]" 
    Debug.Print "myItem.SentOnBehalfOfName:" & "x " & myItem.SentOnBehalfOfName & " x" 

    ' be careful to put this after updating SentOnBehalfOfName 
    myItem.Display 
    ' Manually display the From field to see the updated entry 

Else 

    Debug.Print "Wrong path." 

End If 

ExitRoutine: 
    Set myItem = Nothing 
    Set oExpl = Nothing 

End Sub