Outlook script macro issue

J

Javier Martínez

Hi,

I've created a script for use with a rule in Rules Wizard and have put it
into a module in my VbaProject.OTM. The first times that the rule runs it
works fine. However, after some time it stops working without giving any warn
or error. It seems like if it doesn't execute.

The only way I have found to make it work again is deleting the
VbaProject.OTM, restarting Outlook and typing the macro again. The problem is
that it stops working again after some executions.

Do you know any possible solution to this? I'm using Microsoft Office
Outlook 2007 (12.0.6316.5000) SP1 MSO (12.0.6320.5000).

The script is as follows:
==================
Sub RemoveDoubleRE(Item As Outlook.MailItem)

Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem

Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(Item.EntryID)

olMail.Subject = Replace(olMail.Subject, "RE: ", "Re: ")
olMail.Subject = Replace(olMail.Subject, "Re: ", "Re: ")

While InStr(olMail.Subject, "Re: Re: ") > 0
olMail.Subject = Replace(olMail.Subject, "Re: Re: ", "Re: ")
Wend

olMail.Save

Set olMail = Nothing
Set olNS = Nothing

GC.Collect
GC.WaitForPendingFinalizers

End Sub
==================

Thanks in advance,
Javier
 
J

Javier Martínez

What are the GC.* lines good for?

I don't know it exactly. Reading a forum someone recommended putting them at
the end of the script. I tried to solve me problem with them but it remains
the same. So the script stops working with and without those lines.
 
K

Ken Slovak - [MVP - Outlook]

The GC lines are not something that should be in an Outlook macro or script.
They are for calling the managed code garbage collector when using a
language like C# or VB.NET, not for VBA code.
 
J

Javier Martínez

OK. I deleted them but the problem persists. After some executions the script
stops working without giving any notice.

Regards,
Javier
 
K

Ken Slovak - [MVP - Outlook]

Any error in a rule script will disable that script and the rule. Is your
rule being disabled? If so you have to look to see what errors are being
generated by your code.
 
J

Javier Martínez

First of all thanks for your help.

Curiously when it stops working the rule remains active in the rules
configuration option. In fact, its checkbox is still marked. If there were
any errors, where could I find them and wouldn’t it fail always instead of
after some right executions?
 
K

Ken Slovak - [MVP - Outlook]

Normally it would disable the rule if the script threw an error and since
you have no error handling there I'd expect to see an error message if the
script code did fire an error.

It's possible that only certain items are causing errors, but that doesn't
explain it not showing any error messages. About the only thing I can think
of would be to simplify and temporarily comment out most of the script code
and see if it stops running then. If it doesn't then uncomment lines one at
a time and see when it stops running.
 
J

Javier

Hello,

I think I have solved the problem.

I did some changes in the script that you can see below, but even with that
changes my problem persists. Nevertheless I have found a way to make it work
at least until now.

What I have done is to put the invokation to the script in a rule that also
changes the category of the received emails. So the rule has two actions:
update the category of the email and exectue my script. Since I did this
change the script has worked non-stop.

Final script:
========== CODE =========Sub MacroRE(Item As Outlook.MailItem)
On Error GoTo MacroRE_err

Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim newSubject As String

Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(Item.EntryID)

newSubject = Replace(newSubject, "Re: ", "RE: ")newSubject =
Replace(newSubject, "RE: RE: ", "RE: ")
newSubject = Replace(newSubject, "RE: RE: ", "RE: ")
newSubject = Replace(newSubject, "RE: RE: ", "RE: ")
newSubject = Replace(newSubject, "RE: RE: ", "RE: ")
'While InStr(1, olMail.Subject, "RE: RE: ") > 0
' newSubject = Replace(newSubject, "RE: RE: ", "RE: ")
'Wend

If newSubject <> olMail.Subject Then
olMail.Subject = newSubject
olMail.Save
End If

' Clear memory
MacroRE_exit:
Set olMail = Nothing
Set olNS = Nothing
Exit Sub
' Handle errors
MacroRE_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: MacroRE" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume MacroRE_exit
End Sub
======== END CODE ========

Regards,
Javier
 
V

Vlad G.

I have the same problem but in Outlook 2003. How can I use the code below (Sub MacroRE)in my case?
Thank's in advance



Javie wrote:

Hello,I think I have solved the problem.
27-Nov-08

Hello

I think I have solved the problem

I did some changes in the script that you can see below, but even with that
changes my problem persists. Nevertheless I have found a way to make it work
at least until now

What I have done is to put the invokation to the script in a rule that also
changes the category of the received emails. So the rule has two actions:
update the category of the email and exectue my script. Since I did this
change the script has worked non-stop

Final script
========== CODE =========Sub MacroRE(Item As Outlook.MailItem
On Error GoTo MacroRE_er

Dim olNS As Outlook.NameSpac
Dim olMail As Outlook.MailIte
Dim newSubject As Strin

Set olNS = Application.GetNamespace("MAPI"
Set olMail = olNS.GetItemFromID(Item.EntryID

newSubject = Replace(newSubject, "Re: ", "RE: ")newSubject =
Replace(newSubject, "RE: RE: ", "RE: "
newSubject = Replace(newSubject, "RE: RE: ", "RE: "
newSubject = Replace(newSubject, "RE: RE: ", "RE: "
newSubject = Replace(newSubject, "RE: RE: ", "RE: "
'While InStr(1, olMail.Subject, "RE: RE: ") >
' newSubject = Replace(newSubject, "RE: RE: ", "RE: "
'Wen

If newSubject <> olMail.Subject The
olMail.Subject = newSubjec
olMail.Sav
End I

' Clear memor
MacroRE_exit
Set olMail = Nothin
Set olNS = Nothin
Exit Su
' Handle error
MacroRE_err
MsgBox "An unexpected error has occurred."
& vbCrLf & "Please note and report the following information."
& vbCrLf & "Macro Name: MacroRE"
& vbCrLf & "Error Number: " & Err.Number
& vbCrLf & "Error Description: " & Err.Description
, vbCritical, "Error!
Resume MacroRE_exi
End Su
======== END CODE =======

Regards
Javie

:

Previous Posts In This Thread:

Outlook script macro issue
Hi

I've created a script for use with a rule in Rules Wizard and have put it
into a module in my VbaProject.OTM. The first times that the rule runs it
works fine. However, after some time it stops working without giving any warn
or error. It seems like if it doesn't execute

The only way I have found to make it work again is deleting the
VbaProject.OTM, restarting Outlook and typing the macro again. The problem is
that it stops working again after some executions

Do you know any possible solution to this? I'm using Microsoft Office
Outlook 2007 (12.0.6316.5000) SP1 MSO (12.0.6320.5000)

The script is as follows
=================
Sub RemoveDoubleRE(Item As Outlook.MailItem

Dim olNS As Outlook.NameSpac
Dim olMail As Outlook.MailIte

Set olNS = Application.GetNamespace("MAPI"
Set olMail = olNS.GetItemFromID(Item.EntryID

olMail.Subject = Replace(olMail.Subject, "RE: ", "Re: "
olMail.Subject = Replace(olMail.Subject, "Re: ", "Re: "

While InStr(olMail.Subject, "Re: Re: ") >
olMail.Subject = Replace(olMail.Subject, "Re: Re: ", "Re: "
Wen

olMail.Sav

Set olMail = Nothin
Set olNS = Nothin

GC.Collec
GC.WaitForPendingFinalizer

End Su
=================

Thanks in advance
Javier

What are the GC.* lines good for?
What are the GC.* lines good for

-
Best regard
Michael Bauer - MVP Outloo


Am Tue, 11 Nov 2008 07:40:01 -0800 schrieb Javier Mart?nez

war
is

I don't know it exactly.
I don't know it exactly. Reading a forum someone recommended putting them at
the end of the script. I tried to solve me problem with them but it remains
the same. So the script stops working with and without those lines

:

The GC lines are not something that should be in an Outlook macro or script.
The GC lines are not something that should be in an Outlook macro or script.
They are for calling the managed code garbage collector when using a
language like C# or VB.NET, not for VBA code.





OK. I deleted them but the problem persists.
OK. I deleted them but the problem persists. After some executions the script
stops working without giving any notice.

Regards,
Javier

:

Any error in a rule script will disable that script and the rule.
Any error in a rule script will disable that script and the rule. Is your
rule being disabled? If so you have to look to see what errors are being
generated by your code.





First of all thanks for your help.
First of all thanks for your help.

Curiously when it stops working the rule remains active in the rules
configuration option. In fact, its checkbox is still marked. If there were
any errors, where could I find them and wouldn???t it fail always instead of
after some right executions?



:

Normally it would disable the rule if the script threw an error and since you
Normally it would disable the rule if the script threw an error and since
you have no error handling there I'd expect to see an error message if the
script code did fire an error.

It's possible that only certain items are causing errors, but that doesn't
explain it not showing any error messages. About the only thing I can think
of would be to simplify and temporarily comment out most of the script code
and see if it stops running then. If it doesn't then uncomment lines one at
a time and see when it stops running.





Hello,I think I have solved the problem.
Hello,

I think I have solved the problem.

I did some changes in the script that you can see below, but even with that
changes my problem persists. Nevertheless I have found a way to make it work
at least until now.

What I have done is to put the invokation to the script in a rule that also
changes the category of the received emails. So the rule has two actions:
update the category of the email and exectue my script. Since I did this
change the script has worked non-stop.

Final script:
========== CODE =========Sub MacroRE(Item As Outlook.MailItem)
On Error GoTo MacroRE_err

Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim newSubject As String

Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(Item.EntryID)

newSubject = Replace(newSubject, "Re: ", "RE: ")newSubject =
Replace(newSubject, "RE: RE: ", "RE: ")
newSubject = Replace(newSubject, "RE: RE: ", "RE: ")
newSubject = Replace(newSubject, "RE: RE: ", "RE: ")
newSubject = Replace(newSubject, "RE: RE: ", "RE: ")
'While InStr(1, olMail.Subject, "RE: RE: ") > 0
' newSubject = Replace(newSubject, "RE: RE: ", "RE: ")
'Wend

If newSubject <> olMail.Subject Then
olMail.Subject = newSubject
olMail.Save
End If

' Clear memory
MacroRE_exit:
Set olMail = Nothing
Set olNS = Nothing
Exit Sub
' Handle errors
MacroRE_err:
MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: MacroRE" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"
Resume MacroRE_exit
End Sub
======== END CODE ========

Regards,
Javier

:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Get Silverlight 4 Installed: Tips and Tricks
http://www.eggheadcafe.com/tutorial...b-f54c56a64ed9/get-silverlight-4-install.aspx
 
M

Michael Bauer [MVP - Outlook]

The code should also work with OL03. Do you get any errors?

--
Best regards
Michael Bauer - MVP Outlook
Category Manager - Manage and share your categories:
SAM - The Sending Account Manager:
<http://www.vboffice.net/product.html?lang=en>


Am Sun, 25 Apr 2010 04:38:22 -0700 schrieb Vlad G.:
 

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