Consulting

Results 1 to 4 of 4

Thread: Only run if certain account is being used

  1. #1
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location

    Only run if certain account is being used

    Hi there

    I am using the code below to BCC a group of people but I only want it to work when sending from one account (because I send automated mail from excel from Item(4) account I don't want the question of BCC being asked!).

    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
        Dim objRecip As Recipient
        Dim strMsg As String
        Dim res As Integer
        Dim strBcc As String
        Dim acc As Outlook.Application
        On Error Resume Next
        Set acc = CreateObject("Outlook.Application")
        If acc.Session.Accounts.Item(1) Then
            res = MsgBox("Do you want to add Fringe BCC's?", vbYesNo, "Add Fringe contacts to BCC?")
            If res = vbNo Then Exit Sub
            strBcc = "BCC Fringe"
            Set objRecip = Item.Recipients.Add(strBcc)
            objRecip.Type = olBCC
            If Not objRecip.Resolve Then
                strMsg = "Could not resolve the Bcc recipient. " & _
                "Do you want still to send the message?"
                res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
                "Could Not Resolve Bcc Recipient")
                If res = vbNo Then
                    Cancel = True
                End If
            End If
        End If
        Set objRecip = Nothing
        Set acc = Nothing
    End Sub
    The code in red is what I thought would do this but in runs true regardless of the account I'm sending from.

    What have I done wrong?

    Any help appreciated, thanks

    Paul Ked
    Semper in excretia sumus; solum profundum variat.

  2. #2
    Try replacing the line with
    If Item.SendUsingAccount = "account name" Then
    where account name is the display name of the account.
    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
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Thank you, I will give that a go when I get home this evening.
    Semper in excretia sumus; solum profundum variat.

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Great! Job done, thank you.
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

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