Replace only part of subject in OUTLOOK 2003

Status
Not open for further replies.
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_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
wrote:

Previous Posts In This Thread:

On Tuesday, November 11, 2008 10:40 AM

Javier Mart?ne wrote:

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

On Tuesday, November 11, 2008 4:20 PM

Michael Bauer wrote:

What are the GC.* lines good for?

What are the GC.* lines good for?

Best regards

Michael Bauer

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

warn

is

On Wednesday, November 12, 2008 2:17 AM

JavierMartne wrote:

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.

"Michael Bauer " wrote:

On Wednesday, November 12, 2008 9:21 AM
- wrote:

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.

"Javier Mart??nez" <JavierMartnez> wrote in message

news:6B8C8290-948A-4997-83F9-916EB7BE1DC9@microsoft.com...

On Wednesday, November 12, 2008 11:03 AM

JavierMartne wrote:

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
wrote:

On Wednesday, November 12, 2008 1:53 PM
- wrote:

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.

"Javier Mart??nez" <JavierMartnez> wrote in message

news:DB9E8B2B-4451-4E53-AA19-04AC73E74613@microsoft.com...

On Wednesday, November 12, 2008 3:42 PM

JavierMartne wrote:

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?
wrote:

On Wednesday, November 12, 2008 4:21 PM
- wrote:

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.

"Javier Mart??nez" <JavierMartnez> wrote in message

news:E812E365-FCDA-4E51-85BA-C5E4CA356B2F@microsoft.com...

On Thursday, November 27, 2008 12:55 PM

Javie wrote:

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
wrote:

Get Silverlight 4 Installed: Tips and Tricks

http://www.eggheadcafe.com/tutorial...b-f54c56a64ed9/get-silverlight-4-install.aspx
 
The code should also work with OL03. Do you get any errors?

Best regards

Michael Bauer

Am Sun, 25 Apr 2010 04:38:22 -0700 schrieb 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_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

> " - " wrote:

> Previous Posts In This Thread:

> On Tuesday, November 11, 2008 10:40 AM
> Javier Mart?ne wrote:

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

> On Tuesday, November 11, 2008 4:20 PM
> Michael Bauer wrote:

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

> > Best regards
> Michael Bauer

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

> warn
> is

> On Wednesday, November 12, 2008 2:17 AM
> JavierMartne wrote:

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

> "Michael Bauer " wrote:

> On Wednesday, November 12, 2008 9:21 AM
> - wrote:

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

> >

>

> "Javier Mart??nez" <JavierMartnez> wrote in


message
> news:6B8C8290-948A-4997-83F9-916EB7BE1DC9@microsoft.com...

> On Wednesday, November 12, 2008 11:03 AM
> JavierMartne wrote:

> 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

> " - " wrote:

> On Wednesday, November 12, 2008 1:53 PM
> - wrote:

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

> >

>

> "Javier Mart??nez" <JavierMartnez> wrote in


message
> news:DB9E8B2B-4451-4E53-AA19-04AC73E74613@microsoft.com...

> On Wednesday, November 12, 2008 3:42 PM
> JavierMartne wrote:

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

> " - " wrote:

> On Wednesday, November 12, 2008 4:21 PM
> - wrote:

> 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.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
O Replace hard returns with soft returns on selected text and button to QAT Using Outlook 5
Beeto Replace a string in body Outlook VBA and Custom Forms 2
O How to find and replace a word in Outlook-Agenda-Subject and Message? Using Outlook 0
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
M Outlook 2013 Replace Subject with Conversation (a "hidden" value). Outlook VBA and Custom Forms 0
F Copy and replace not update contact in another pst Using Outlook 0
C How to replace or delete first instance of sentence in mail body? Outlook VBA and Custom Forms 1
C replace subject line generated by converting a word document to PDF and sending it to an email Using Outlook 8
Diane Poremsky How to perform a global search and replace Using Outlook 0
B Delete/replace old files and save new attachments Using Outlook 1
Diane Poremsky Replace Display Names with Email Addresses Using Outlook 0
mrje1 Is there a Find and Replace feature in Outlook 2016? Using Outlook 4
J Pull an email address from body and replace reply-to address Outlook VBA and Custom Forms 4
divan Outlook 2007 - Replace email body with custom text Using Outlook 9
E VBScript to replace module? Using Outlook 3
A How to replace column title in address book Using Outlook 1
A Replace olFolderContacts for Sharepoint lists in Outlook Outlook VBA and Custom Forms 5
P replace default outlook form with custom form Outlook VBA and Custom Forms 1
A How to replace getcontactsfolder (ol2007) in Outlook 2003 Outlook VBA and Custom Forms 2
A Outlook 365 Outlook (part of 365) now working offline - argh Using Outlook 5
S Conditional Formatting in calendar part of To-Do Bar Using Outlook 1
S Received mail as part of DL, need to auto-CC the same when replying Outlook VBA and Custom Forms 5
H Search and delete part of a link inside HTML body message Outlook VBA and Custom Forms 2
M Upgrade in Progress. Your mailbox is currently being optimized as part of upgrade to Outlook 2010 Using Outlook 9
L auto copy text in mail body to other part of the body Outlook VBA and Custom Forms 1
G Not receiving email when sent as part of a group Using Outlook 5
S Outlook 2010 and Multi-Part MIME Messages Using Outlook 2
E Accessing User Defined Fields in BCM Database part 2 BCM (Business Contact Manager) 0
E [SOLVED] Accessing User Defined Fields in BCM Database part 1 BCM (Business Contact Manager) 9
R Access Program Only Looping Part Way Through Outlook Inbox Outlook VBA and Custom Forms 2
E hot to get the email address of an outlook mail item from "on behalf of" part Outlook VBA and Custom Forms 1
H using VBA to edit subject line Outlook VBA and Custom Forms 0
F Auto changing email subject line in bulk Using Outlook 2
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
J Outlook 365 Forward Email Subject to my inbox when new email arrive in shared inbox Using Outlook 0
sjmo2 Change subject for new e-mails only. Outlook VBA and Custom Forms 2
C Outlook 365 Copy/Save Emails in Folder Outside Outlook to Show Date Sender Recipient Subject in Header Using Outlook 0
D Prompt to prefix subject line whenever sending an email Outlook VBA and Custom Forms 3
ill13 Prepend the user's computer name to the subject. Outlook VBA and Custom Forms 1
D Auto Remove [EXTERNAL] from subject - Issue with Macro Using Outlook 21
2 How to get rid of the "Emailing:" prefix in the subject line Using Outlook 1
S Outlook Macro for [Date][Subject] Using Outlook 1
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
C Outlook 365 Subject Prefixes? Outlook VBA and Custom Forms 1
A Macro to file emails into subfolder based on subject line Outlook VBA and Custom Forms 1
N Save selected messages VBA does not save replies and/or messages that contain : in subject Outlook VBA and Custom Forms 1
V vBA for searching a cell's contents in Outlook and retrieving the subject line Outlook VBA and Custom Forms 1
C Macro to extract sender name & subject line of incoming emails to single txt file Outlook VBA and Custom Forms 3
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1

Similar threads

Back
Top