A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

VBA scripts sometimes fail to run...



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 2nd 07, 04:08 AM posted to microsoft.public.outlook.program_vba
Lanceford
external usenet poster
 
Posts: 8
Default VBA scripts sometimes fail to run...

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
  #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

  #3  
Old January 2nd 07, 10:51 AM posted to microsoft.public.outlook.program_vba
Lanceford
external usenet poster
 
Posts: 8
Default VBA scripts sometimes fail to run...

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

How do I do this?

Thanks.


  #4  
Old January 2nd 07, 12:56 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default VBA scripts sometimes fail to run...



In VB you can simply delete the 'ByVal'. You can (but don't have to) replace
it by 'ByRef'.

--
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 17:51:13 +0800 schrieb 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.

  #5  
Old January 3rd 07, 06:18 AM posted to microsoft.public.outlook.program_vba
Lanceford
external usenet poster
 
Posts: 8
Default VBA scripts sometimes fail to run...

Thanks.



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA-run-through stopping after abount 250 items Allan Outlook and VBA 6 September 26th 06 11:04 PM
Run VBA code on receipt of e-mail White Horse Outlook and VBA 2 August 28th 06 09:51 PM
VBA Scripts Do Not Show Up As "Custom Actions" [email protected] Outlook and VBA 4 April 26th 06 10:29 PM
Run VBA Code from 'new mail message' on standard toolbar Carmi Outlook and VBA 8 March 31st 06 06:53 PM
Message Rule Does Not Run VBA Procedure Lowell Outlook and VBA 18 March 9th 06 07:47 PM


All times are GMT +1. The time now is 08:43 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.