Consulting

Results 1 to 6 of 6

Thread: VBA to add a bcc

  1. #1

    VBA to add a bcc

    New to the forum; can anyone help me with the VBA code to add a specific bcc address to selected emails in the draft folder?

    It needs to be run on just the selected drafts - not the entire folder or a global rule.

    It's times like this I wish Outlook VBA had a macro recorder like its siblings Word and Excel!

    Anyone?

    Any help much appreciated.

  2. #2
    Maybe something like

    Sub AddBCC()
    Dim olFolder As Outlook.Folder
    Dim olItem As Outlook.MailItem
    Dim strBCC As String
        On Error Resume Next
        strBCC = "someone@somewhere.com"
        Set olFolder = Session.GetDefaultFolder(olFolderDrafts)
        For Each olItem In ActiveExplorer.Selection
            If olItem.Parent = olFolder And TypeName(olItem) = "MailItem" Then
                olItem.Recipients.Add(strBCC).Type = 3
                olItem.Save
            End If
        Next olItem
    lbl_Exit:
        Set olFolder = Nothing
        Set olItem = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3

    Almost...

    Thanks for this, Graham. Running the code adds the name of the recipient, but to the "Send To" field.

    What should the code be for adding it to the Bcc field instead?

    Very grateful for your input.

    Warren

  4. #4
    The line
    olItem.Recipients.Add(strBCC).Type = 3
    adds the name defined in strBCC as BCC. Type = 3 is BCC.
    If there is no existing BCC, you could probably use
    olItem.BCC = strBCC
    instead of the above line.
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  5. #5
    Quote Originally Posted by gmayor View Post
    The line
    olItem.Recipients.Add(strBCC).Type = 3
    adds the name defined in strBCC as BCC. Type = 3 is BCC.
    If there is no existing BCC, you could probably use
    olItem.BCC = strBCC
    instead of the above line.
    That works perfectly now thanks, Graham.

    The macro runs from the Developer window, but when I assign it to a button on the QAT and click it, it does nothing. Same with other macros, but if I add buttons for the built-in commands, like say "Reply", they work.

    Would you happen to know if there is a setting I need to make in Outlook to get macros to run from the QAT? I have no such problems running macros from Excel and Word QATs...

    Thanks again

    W

  6. #6
    I can't think of one and it runs from the QAT here.
    There can be a security issue with Outlook - see
    https://www.gmayor.com/create_and_em...gital_cert.htm
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •