VBA scripts sometimes fail to run...

L

Lanceford

I am having problems with VBA scripts sometimes failing to run.

I have a script to send BCC's on all emails, however sometimes it fails to
run, sometimes it runs fine. When it fails to run, there is no error
message.

I have noticed that when the scripts fail to run, it does so for for an
entire period of time. I have not been able to recreate the scripts failing
to execute, however if I look in the account that messages are BCC'd to I
can see that for 24 hours here and for 3 hours there the script failed to
execute.


I don't think the problem is with the script, however here is the script.

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

Call AddBCC(Item, Cancel, (e-mail address removed))

End Sub

Private Sub AddBCC(ByVal Item As Object, ByVal Cancel As Boolean, strBcc As
String)
Dim objRecip As Recipient
Dim strMsg As String
Dim res As Integer

On Error Resume Next
Set objRecip = Item.Recipients.Add(strBcc)
' handle case of user canceling Outlook security dialog
If Err = 287 Then
strMsg = "Could not add a Bcc recipient " & _
"because the user said No to the security prompt." & _
" Do you want still to send the message?"
res = MsgBox(strMsg, vbYesNo + vbDefaultButton1, _
"Security Prompt Cancelled")
If res = vbNo Then
Cancel = True
Else
objRecip.Delete
End If
Err.Clear
Else
objRecip.Type = olBCC
objRecip.Resolve
If Not objRecip.Resolved 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

End Sub
 
L

Lanceford

BTW, in AddBCC you must declare the
Cancel argument as ByRef, else it won't be passed back.

How do I do this?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top