ljefi
05-12-2015, 02:12 AM
Hi,
I have produced a macro attached to a button on the Outlook 2010 ribbon which adds "[OFFICIAL-SENSITIVE]" to the subject line when clicked by the users, allowing them to flag up sensitive emails.
My problem is that olMail.Subject doesn't seem able to read the value held in subject until the user has clicked out of the subject line box.
This causes two problems;
The user types their subject, then clicks the macro without moving the cursor from subject - their keyed in subject is overwritten with [OFFICIAL-SENSITIVE], using a message box proves that olMail.Subject is returning blank. If I type a subject, click out of the subject box and then click the macro the [OFFICIAL-SENSITIVE] label is appended to the subject as expected.
If the user accidentally removes/deletes the [OFFICIAL-SENSITIVE] label from their subject clicking the button again, the macro does not replace the label until they have clicked out of the subject box, this is because olMail.Subject is still returning the previous value which still includes [OFFICIAL-SENSITIVE]
I've tried using send keys to send a TAB character (and I assumed leave the subject box) but this made no difference.
Is there a way to explicitly give the message body the focus.
Any ideas?
Here's the code;
Dim strSubject As String
Dim strLabel As String
strSubject = ""
strLabel = "[OFFICIAL-SENSITIVE]"
Dim olMail As MailItem
Set olMail = ActiveInspector.CurrentItem
strSubject = olMail.Subject
'Check if the subject already includes the label
Contains = InStr(strSubject, strLabel)
'If not then add the label
If Contains = False Then
olMail.Subject = ""
olMail.Subject = strLabel & strSubject
End If
Any suggestions appreciated!
Regards
Lee
I have produced a macro attached to a button on the Outlook 2010 ribbon which adds "[OFFICIAL-SENSITIVE]" to the subject line when clicked by the users, allowing them to flag up sensitive emails.
My problem is that olMail.Subject doesn't seem able to read the value held in subject until the user has clicked out of the subject line box.
This causes two problems;
The user types their subject, then clicks the macro without moving the cursor from subject - their keyed in subject is overwritten with [OFFICIAL-SENSITIVE], using a message box proves that olMail.Subject is returning blank. If I type a subject, click out of the subject box and then click the macro the [OFFICIAL-SENSITIVE] label is appended to the subject as expected.
If the user accidentally removes/deletes the [OFFICIAL-SENSITIVE] label from their subject clicking the button again, the macro does not replace the label until they have clicked out of the subject box, this is because olMail.Subject is still returning the previous value which still includes [OFFICIAL-SENSITIVE]
I've tried using send keys to send a TAB character (and I assumed leave the subject box) but this made no difference.
Is there a way to explicitly give the message body the focus.
Any ideas?
Here's the code;
Dim strSubject As String
Dim strLabel As String
strSubject = ""
strLabel = "[OFFICIAL-SENSITIVE]"
Dim olMail As MailItem
Set olMail = ActiveInspector.CurrentItem
strSubject = olMail.Subject
'Check if the subject already includes the label
Contains = InStr(strSubject, strLabel)
'If not then add the label
If Contains = False Then
olMail.Subject = ""
olMail.Subject = strLabel & strSubject
End If
Any suggestions appreciated!
Regards
Lee