View Single Post
  #2  
Old January 2nd 07, 06:59 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default VBA scripts sometimes fail to run...



Why do you know that no error occurs? BTW, in AddBCC you must declare the
Cancel argument as ByRef, else it won't be passed back.

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Keep your Outlook categories organized!
http://www.shareit.com/product.html?...4&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am Tue, 2 Jan 2007 11:08:51 +0800 schrieb 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, )

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

Ads