Help with macro to insert text

rparker85

New Member
Joined
Jan 27, 2011
Messages
7
Hey Everyone!!

I'm hoping I can get a little help with this macro. It's for Outlook... but I know you are all experts with macros. :)

I made a macro (pieced together from various google sources) that will insert TEXT at the start of an email subject line when I send, reply, reply all, or forward an email. If the subject line already contains TEXT then it will send the subject line as is. What I would like to add in is if the subject line starts with "// " then the email would send the subject line less the // .

Example -
Subject: This is an email --> Subject: TEXT This is an email
Subject: TEXT This is an email --> Subject: TEXT This is an email
Subject: // This is an email --> Subject: This is an email

I thought I had it all put together; however when replying or forwarding an email it would send a subject like "Subject: TEXT FW: TEXT This is an email" and I don't want it to keep tacking on the TEXT every time I reply/forward.

Can anyone help me out with this? Below is the macro I have right now.

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

subject_line = Trim(Item.Subject)

If InStr(1, UCase(subject_line), "TEXT ") <> 1 Then
Item.Subject = "TEXT " & subject_line
Else
Item.Subject = subject_line
End If
End Sub


Thanks!!
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I thnk the problem is with the line:

If InStr(1, UCase(subject_line), "TEXT ") <> 1 Then

I think it's looking for TEXT to always be at the start of the subject; however when you reply or forward outlook will add RE: or FW: to the start of the subject. On a long email chain I'll end up with a subject full of TEXT RE: TEXT RE: TEXT RE: TEXT RE:... which I do not want. So I think I need the macro to search for "TEXT" to be anywhere within the subject and not just at the start?
 
Upvote 0

Forum statistics

Threads
1,224,548
Messages
6,179,453
Members
452,915
Latest member
hannnahheileen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top