Link to home
Start Free TrialLog in
Avatar of Kev
KevFlag for Australia

asked on

Need Macro to Auto Insert e-mail Subject

Hi,

I need to create a macro that when run (preferably from a button on the tool bar) auto inserts the following text "SEC: UNCLAS" in the subject field of the current email.

I am reasonable with VB and VBA, however, I have never used VBA with MS Outlook. Any urgent assistance is greatly appreciated.

Kev
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Kev.

The code for adding the subject is extremely simple.  Something like this:

    Sub InsertSubject()
        Application.ActiveInspector.CurrentItem.Subject = SEC: UNCLAS"
    End Sub

Hooking it to a button can be handled in two ways: manual or automatic.  The manual approach requires you to follow a series of steps to create the button.  The automatic approach employs code that checks to see if the button exists and creates it if it doesn't.  Let me know which solution you prefer and I'll post the necessary instructions and code (if needed).

Cheers!
Avatar of Kev

ASKER

Hi Guys,

Thanks both for the solutions you have provided.

I have just realised that I may also need to add the SEC: UNClAS to emails being fwd on. Is there a way to add SEC: UNclas to the beginning to the current subject line.

I would also like very much the code to autocreate the button. I can manually create a button, but I do not want to set this up for all pers within my organisation.

Apologies for the slow reply, I was in meetings pretty much all day yesterday.

Regards

Kev.

> I have just realised that I may also need to add the SEC: UNClAS to emails being fwd on. Is there
> a way to add SEC: UNclas to the beginning to the current subject line.

To change it so that the string gets inserted at the beginning of the subject, change:

    olMsg.Subject = "SEC: UNCLAS"

to:

    olMsg.Subject = "SEC: UNCLAS" & IIf(olMsg.Subject = "", "", " " & olMsg.Subject)

Patrick
Avatar of Kev

ASKER

Hi MathewsPatrick,

The amended code you have provided is perfect, thanks. I will award you at least 50% of the points. I am just waiting to see if BlueDevilFan is able to provide the code to automatically setup the macro buttons.

Once again, Thanks very much.

Kev
Sorry, Kev.  I missed that part of your post.  Hang on a second and I'll post the button code.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That all worked.  You are imazing!!!  How and where can I get some Outlook smarts,  I have looked and googled and found some interesting stuff,  but no code for the various events and objects that do this kind of magic.

Thank you Sir,
Howard