PDA

View Full Version : [SOLVED:] Only run if certain account is being used



paulked
04-19-2019, 07:44 AM
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

gmayor
04-19-2019, 10:08 PM
Try replacing the line with

If Item.SendUsingAccount = "account name" Thenwhere account name is the display name of the account.

paulked
04-20-2019, 02:28 AM
Thank you, I will give that a go when I get home this evening.

paulked
04-20-2019, 08:49 AM
Great! Job done, thank you.