none
VBA code to read bcc field RRS feed

  • Question

  • VBA code to read bcc field and attach signature depending on bcc field. I know how to add an email to a bcc field but I need to read it. Can some help me please
    Friday, June 29, 2012 3:22 PM

Answers

All replies

  • Read either MailItem.BCC property or loop through the MailItem.Recipioents colelction and check if the Recipient.Type property for each recipient is equal olBCC.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, June 29, 2012 3:42 PM
  • This is what I have:

    Dim objmail As Outlook.MailItem
    Dim objRecip As Recipient
    Dim strBcc As String
    strBcc = objmail.BCC
    MsgBox strBcc

    I am new to VBA

    Friday, June 29, 2012 4:02 PM
  • What is wrong? Are you saying the BCC property is empty?  To/CC/BCC properties are updated based on the mesage recipients when te message is saved.

    Are you looking for a particular e-mail address? Try something like the following

    bFound = false
    for each Recip in objmail.Recipients
      if StrComp(Recip.Address, "someuser@domain.com") = 0 Then
        bFound = true
        Exit For
      End If
    next
    if bFound  Then
      MessageBox "Gotcha!"
    End If


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, June 29, 2012 5:55 PM
  • I got Object required on line:

    For Each Recip In objmail.Recipients

    Friday, June 29, 2012 6:17 PM
  • Where does objmail come from? Are you sure it is not null?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, June 29, 2012 8:00 PM
  • I go to compose a new  mail and fill out the To and BCC fireld. I also fill out the subject. And when I hit the Send button that is when I get the error.
    Friday, June 29, 2012 8:07 PM
  • You need to initialize that variable.

    Something like the following should the job:

    set objmail = Application.ActiveInspector.CurrentItem


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.3 is now available!

    Friday, June 29, 2012 9:32 PM