'Control contents of email address fields

I want to send the body of a Word document as an email from MS Word 2016.

I want the user to select recipients from the address book. I want them to only be put in the BCC field.

How do I monitor the to/from/CC/BCC fields for changes, and then move those changes to BCC?

The documentation indicates the use of Inspectors, but nothing specific about accessing the contents of these fields.

I have two approaches:

  • open a new Outlook mail item, load the contents of the Word file to it, and then try to monitor the fields that way.
  • send directly from Word using the Quick Access Toolbar option "Send to Mail Recipient".
    I don't know if that is an option based on what I was reading and if those fields are accessible via VBA.

Code example of what I have so far:

Sub SendDocumentInMail()

Dim bStarted As Boolean
Dim oOutlookApp As Outlook.Application
Dim oItem As Outlook.MailItem

On Error Resume Next

'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
    'Outlook wasn't running, start it from code
    Set oOutlookApp = CreateObject("Outlook.Application")
    bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)

With oItem
    'Set the recipient for the new email
   .To = "[email protected]"
    'Set the recipient for a copy
    .CC = "[email protected]"
    'Set the subject
    .Subject = "New subject"
    'The content of the document is used as the body for the email
    .Body = ActiveDocument.Content
    .Send
End With

If bStarted Then
    'If we started Outlook from code, then close it
    oOutlookApp.Quit
End If

'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing

End Sub


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source