Highlight text in Outlook 2013

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
morxy49
Posts: 21
Joined: 04 Aug 2016, 03:44

Highlight text in Outlook 2013

Post by morxy49 » 03 Apr 2018, 06:07

Hi,

I'm trying to create a script that highlights all occurrences of a specific type of string inside of an email in Outlook 2013 (both in the body and the subject field if possible).

I want to highlight all occurrences of a 8-digit number beginning with either "00" or just "0" (for example "00837928").
I also want to highlight all occurrences of a word starting with "IC-" and is followed by a 6-digit number (for example "IC-323036") - but this should be highlighted in another color!

Is anyone able to help me with this? I don't really know where to begin, and if it's even possible.

morxy49
Posts: 21
Joined: 04 Aug 2016, 03:44

Re: Highlight text in Outlook 2013

Post by morxy49 » 05 Apr 2018, 04:32

Does nobody know how to do this? :(

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Highlight text in Outlook 2013

Post by FanaticGuru » 06 Apr 2018, 18:45

Outlook only allows you to highlight text in an email you are composing. You cannot highlight text in emails received. Received are read-only.

Now if you are wanting to do this in emails as you are composing them, then yes that is possible. Emails being composed are created in an editor that is basically a stripped down version of Word that can be accessed with COM with many of the same code you would use on a Word document.

When I get time I will post an example if while composing is what you want.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Highlight text in Outlook 2013

Post by FanaticGuru » 09 Apr 2018, 14:15

Below is code to highlight text in the Outlook email editor.

Code: Select all

F12::
	Email_HighLight("<IC-[0-9]{6}", "<0[0-9]{7}")
return

Email_HighLight(Arr*)
{
	olApp := ComObjActive("Outlook.Application")
	wdApp := olApp.ActiveInspector.WordEditor.Application
	wdApp.Selection.Find.ClearFormatting
	wdApp.Selection.Find.Replacement.ClearFormatting
	wdApp.Selection.Find.Replacement.Highlight := true
	wdApp.Options.DefaultHighlightColorIndex := 6 ; WdColorIndex = 2 blue, 6 red, 7 yellow, 11 green
	wdApp.Selection.Find.Replacement.Text := ""
	for Index, Str in Arr
		wdApp.Selection.Find.Execute(Str,,,1,,,,1,,,2)
}
Only works when composing an email either a new one or a reply but will not work in a received email as those are read-only and cannot be changed.

This uses the Word wildcard system to match so other searches could be used as complex as the wildcard system will allow.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

morxy49
Posts: 21
Joined: 04 Aug 2016, 03:44

Re: Highlight text in Outlook 2013

Post by morxy49 » 10 Apr 2018, 11:34

Thank you for your input! Unfortunately i need this to show up in all emails, not only in composing, so i guess i will have to scrap that idea :/
But thank you anyway for your time! It's appreciated!

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Highlight text in Outlook 2013

Post by FanaticGuru » 10 Apr 2018, 16:09

morxy49 wrote:Thank you for your input! Unfortunately i need this to show up in all emails, not only in composing, so i guess i will have to scrap that idea :/
But thank you anyway for your time! It's appreciated!
On further review, I discovered you can turn off the read-only protection of received emails. And then you can highlight and do pretty much any other edits to the email about the same as when you are composing an email. Add text, change fonts, change styles, etc.

Code: Select all

F12::
	Email_Highlight("<IC-[0-9]{6}", "<0[0-9]{7}")
return

Email_Highlight(Arr*)
{
	olApp := ComObjActive("Outlook.Application")
	wdDoc := olApp.ActiveInspector.WordEditor
	try
		wdDoc.Unprotect
	wdApp := wdDoc.Application
	wdApp.Selection.Find.ClearFormatting
	wdApp.Selection.Find.Replacement.ClearFormatting
	wdApp.Selection.Find.Replacement.Highlight := true
	wdApp.Options.DefaultHighlightColorIndex := 6 ; WdColorIndex = 2 blue, 6 red, 7 yellow, 11 green
	wdApp.Selection.Find.Replacement.Text := ""
	for Index, Str in Arr
		wdApp.Selection.Find.Execute(Str,,,1,,,,1,,,2)
	;~ olApp.ActiveWindow.CurrentItem.Save ; Uncomment to Save changes
}
You just have to have an email open whether it is composing a new one or just viewing a received one.

Once you save the edited email, it is that way from then on. It is pretty much like that was the way the email was when original received.

This editing of received emails is kind of an interesting idea I had not thought about. Maybe I will have some use for it in the future.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

BartNijs
Posts: 5
Joined: 06 Jan 2022, 07:40

Re: Highlight text in Outlook 2013

Post by BartNijs » 24 Jan 2022, 06:21

Interesting! I wonder if this still works in the latest Outlook versions.
I'm just getting into AHK and am creating some hotkeys for Outlook. I'm using the built in shortcuts for now, but they have limitations. I'm looking into learning the ComObj method now.

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Highlight text in Outlook 2013

Post by FanaticGuru » 24 Jan 2022, 19:42

BartNijs wrote:
24 Jan 2022, 06:21
Interesting! I wonder if this still works in the latest Outlook versions.
I'm just getting into AHK and am creating some hotkeys for Outlook. I'm using the built in shortcuts for now, but they have limitations. I'm looking into learning the ComObj method now.

Just tried the code above on an open received email and it worked fine with the most up to date versions of Outlook in Office 365 with Windows 11.

The Office COM interface has changed very little over time. Lots of third-party programs use it to interact with Office programs and they are hesitant to break all that legacy software.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Post Reply

Return to “Ask for Help (v1)”