How can I add [SEC=UNCLASSIFIED] to the subject line of all new em

G

Guest

I am required to add [SEC=UNCLASSIFIED] to the subject line of all new emails
in Outlook 2007 - how can I do this automatically\programmatically?
 
G

Guest

Create a class and use it as described below; will work with earlier versions
of Outlook as well.

'Class name = clsMailItemTrapper

'**********************************************************
'USAGE:
'Use this class in ThisOutlookSession as follows:

'Option Explicit
'Dim myMailItemTrapper As clsMailItemTrapper

'Private Sub Application_Startup()
' Set myMailItemTrapper = New clsMailItemTrapper
'End Sub
'**********************************************************
Option Explicit
Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objOpenInspector As Outlook.Inspector
Dim WithEvents objMailItem As Outlook.MailItem

Private Sub Class_Initialize()
Set objInspectors = Application.Inspectors
End Sub

Private Sub Class_Terminate()
Set objOpenInspector = Nothing
Set objInspectors = Nothing
Set objMailItem = Nothing
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class = olmail Then
'Only look for new messages
Set objMailItem = Inspector.CurrentItem
If objMailItem.Sent = False Then
Set objOpenInspector = Inspector
Else
Set objMailItem = Nothing
End If
End If
End Sub

Private Sub objMailItem_Open(Cancel As Boolean)
objMailItem.Subject = "[SEC=UNCLASSIFIED]"
End Sub
 
G

Guest

Thanks Eric - I've treid using the code but am used to an older version of
VBA (in Excel) and am confused as to how to use it. Is it also possible to
drop the words sec=unclassified into replies?

Ron

Eric Legault said:
Create a class and use it as described below; will work with earlier versions
of Outlook as well.

'Class name = clsMailItemTrapper

'**********************************************************
'USAGE:
'Use this class in ThisOutlookSession as follows:

'Option Explicit
'Dim myMailItemTrapper As clsMailItemTrapper

'Private Sub Application_Startup()
' Set myMailItemTrapper = New clsMailItemTrapper
'End Sub
'**********************************************************
Option Explicit
Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objOpenInspector As Outlook.Inspector
Dim WithEvents objMailItem As Outlook.MailItem

Private Sub Class_Initialize()
Set objInspectors = Application.Inspectors
End Sub

Private Sub Class_Terminate()
Set objOpenInspector = Nothing
Set objInspectors = Nothing
Set objMailItem = Nothing
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class = olmail Then
'Only look for new messages
Set objMailItem = Inspector.CurrentItem
If objMailItem.Sent = False Then
Set objOpenInspector = Inspector
Else
Set objMailItem = Nothing
End If
End If
End Sub

Private Sub objMailItem_Open(Cancel As Boolean)
objMailItem.Subject = "[SEC=UNCLASSIFIED]"
End Sub


--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


Ron McLay said:
I am required to add [SEC=UNCLASSIFIED] to the subject line of all new emails
in Outlook 2007 - how can I do this automatically\programmatically?
 
G

Guest

FWIW, the VBA editor in all Office apps haven't changed a bit since Office
2000.

Anyway, to get this to work for you, create a new Class in your Outlook VBA
Project and name it "clsMailItemTrapper". Then paste all the code from
before that's below the last line of asterisks. Then add the code listed in
the usage section at the top to the ThisOutlookSession module in the VBA
Project.

You'll need to run the code in the Application_Startup event manually or
restart Outlook before the code will actually work.

For trapping the reply event, see my blog for a walkthrough on gaining this
power and more with any item in Outlook:

Eric Legault My Eggo : Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/pages/20086.aspx

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


Ron McLay said:
Thanks Eric - I've treid using the code but am used to an older version of
VBA (in Excel) and am confused as to how to use it. Is it also possible to
drop the words sec=unclassified into replies?

Ron

Eric Legault said:
Create a class and use it as described below; will work with earlier versions
of Outlook as well.

'Class name = clsMailItemTrapper

'**********************************************************
'USAGE:
'Use this class in ThisOutlookSession as follows:

'Option Explicit
'Dim myMailItemTrapper As clsMailItemTrapper

'Private Sub Application_Startup()
' Set myMailItemTrapper = New clsMailItemTrapper
'End Sub
'**********************************************************
Option Explicit
Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objOpenInspector As Outlook.Inspector
Dim WithEvents objMailItem As Outlook.MailItem

Private Sub Class_Initialize()
Set objInspectors = Application.Inspectors
End Sub

Private Sub Class_Terminate()
Set objOpenInspector = Nothing
Set objInspectors = Nothing
Set objMailItem = Nothing
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class = olmail Then
'Only look for new messages
Set objMailItem = Inspector.CurrentItem
If objMailItem.Sent = False Then
Set objOpenInspector = Inspector
Else
Set objMailItem = Nothing
End If
End If
End Sub

Private Sub objMailItem_Open(Cancel As Boolean)
objMailItem.Subject = "[SEC=UNCLASSIFIED]"
End Sub


--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


Ron McLay said:
I am required to add [SEC=UNCLASSIFIED] to the subject line of all new emails
in Outlook 2007 - how can I do this automatically\programmatically?
 
G

Guest

Eric
It worked - thanks so much. I'm used to recording my actions in an earlier
version and then modifying or adding simple stuff. You are way more
sophisticated than I.

Thank you very much

Ron McLay
IT Services Manager
Human Rights and Equal Opportunity Commission


Eric Legault said:
FWIW, the VBA editor in all Office apps haven't changed a bit since Office
2000.

Anyway, to get this to work for you, create a new Class in your Outlook VBA
Project and name it "clsMailItemTrapper". Then paste all the code from
before that's below the last line of asterisks. Then add the code listed in
the usage section at the top to the ThisOutlookSession module in the VBA
Project.

You'll need to run the code in the Application_Startup event manually or
restart Outlook before the code will actually work.

For trapping the reply event, see my blog for a walkthrough on gaining this
power and more with any item in Outlook:

Eric Legault My Eggo : Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/pages/20086.aspx

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


Ron McLay said:
Thanks Eric - I've treid using the code but am used to an older version of
VBA (in Excel) and am confused as to how to use it. Is it also possible to
drop the words sec=unclassified into replies?

Ron

Eric Legault said:
Create a class and use it as described below; will work with earlier versions
of Outlook as well.

'Class name = clsMailItemTrapper

'**********************************************************
'USAGE:
'Use this class in ThisOutlookSession as follows:

'Option Explicit
'Dim myMailItemTrapper As clsMailItemTrapper

'Private Sub Application_Startup()
' Set myMailItemTrapper = New clsMailItemTrapper
'End Sub
'**********************************************************
Option Explicit
Dim WithEvents objInspectors As Outlook.Inspectors
Dim WithEvents objOpenInspector As Outlook.Inspector
Dim WithEvents objMailItem As Outlook.MailItem

Private Sub Class_Initialize()
Set objInspectors = Application.Inspectors
End Sub

Private Sub Class_Terminate()
Set objOpenInspector = Nothing
Set objInspectors = Nothing
Set objMailItem = Nothing
End Sub

Private Sub objInspectors_NewInspector(ByVal Inspector As Inspector)
If Inspector.CurrentItem.Class = olmail Then
'Only look for new messages
Set objMailItem = Inspector.CurrentItem
If objMailItem.Sent = False Then
Set objOpenInspector = Inspector
Else
Set objMailItem = Nothing
End If
End If
End Sub

Private Sub objMailItem_Open(Cancel As Boolean)
objMailItem.Subject = "[SEC=UNCLASSIFIED]"
End Sub


--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


:

I am required to add [SEC=UNCLASSIFIED] to the subject line of all new emails
in Outlook 2007 - how can I do this automatically\programmatically?
 

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