0

I have a userform combobox that allows users to select a project email. I want to be able to select this email, and click on a button in the userform which loads the email into the CC field. I've got this code right now, but it's giving me an error. Any help is appreciated.

Private Sub Attach_Click()

    Set oMsg = Application.ActiveInspector.CurrentItem
    Dim objRecip As Recipient
    
    Set objRecip = oMsg.Recipients.Add(Me.cmbPC.column(0))
    objRecip.Type = olCC
    
End Sub

Error that pops up:

The operation failed. The messaging interfaces have returned an unknown error. If the problem persists, restart Outlook. Cannot resolve recipient.

help-info.de
  • 6,695
  • 16
  • 39
  • 41

1 Answers1

0

Use the Recipient.Resolve method which attempts to resolve a Recipient object against the Address Book.

Sub CreateAssignedTask()  
 Dim myItem As Outlook.TaskItem  
 Dim myDelegate As Outlook.Recipient  
 Set MyItem = Application.CreateItem(olTaskItem)  
 MyItem.Assign  
 Set myDelegate = MyItem.Recipients.Add("Eugene Astafiev")  

 myDelegate.Resolve  
 If myDelegate.Resolved Then  
    myItem.Subject = "Test task"  
    myItem.Display  
 End If 
 
End Sub

You may find the How To: Fill TO,CC and BCC fields in Outlook programmatically article helpful.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Hi Eugene, thanks for the reply. Would the above code be placed into my combobox code or 'ThisOutlookSession'? – MarkSmith Sep 01 '21 at 07:17