Macro Code Count

Is there a way I can add a command button to outlook?

All of my emails are altered once processed in  the subject bar to read something like -

"hughesr - GE - s. 09/11/08 10:45 am e. 09/11/08 06:00 pm"

What I am hoping to do is count the occurrence of "GE" which are my initials... so anything in the subject bar that wold have "ge" or "GE"  amongst what is typed there.

So ideally I would highlight a range and then hit the command button and it would count the occurrence of "GE"

Please can you help, I have never added a macro to outlook so your help is much appreciated.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is fairly straightforward: add the macro below, then right-click your toolbar and select 'Customize...' Select the 'Commands' tab and click on 'Macros' in the category list. The macro (Project1.Count_Instances) will appear in the 'Commands' list, drag it onto the toolbar and it will create the button. You can then right-click the button and change its name to something more succinct.

Sub Count_Instances()
Dim mi As MailItem, i As Integer
    For Each mi In Application.ActiveExplorer.Selection
        If InStr(1, mi.Subject, "GE") > 0 Then i = i + 1
    MsgBox "There are " & i & " emails with GE in the subject line"
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ah, I didn't read your question fully... you want to find "ge" as well as "GE". That's fine, just change the Instr line to this:

        If InStr(1, UCase(mi.Subject), "GE") > 0 Then i = i + 1
And it's occurred to me that this may be unreliable, as it will also pick out "ge" from any words with those two letters in sequence. If you can guarantee there will always be a space before and after the "GE", as in your example above, you should change the search parameter in the Instr command to " GE "
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.