Outlook M.Reply Help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ThiefUK
Posts: 19
Joined: 25 Jul 2017, 10:23

Outlook M.Reply Help

13 Feb 2018, 11:29

Hi All

I'm trying to generate a reply using COM (I believe it's called) -

I've been attempting m.reply but I'm unsure if that works.

Currently:

m := ComObjActive("Outlook.Application").CreateItem(0)
m.To :=
m.Subject :=
m.display

But that always opens a brand new page.

I need to generate a reply to a thread (an email in my inbox) with a message and attachment, can you help as I've been searching the forums for a few days :(

Thanks,
ThiefUK
Posts: 19
Joined: 25 Jul 2017, 10:23

Re: Outlook M.Reply Help

14 Feb 2018, 09:03

Hi Guys

Any help here would be so grateful -

I've attempted to extract code from here - https://github.com/ahkon/MS-Office-COM- ... strict.ahk

With little success.
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Outlook M.Reply Help

14 Feb 2018, 13:26

Here is an example:

Code: Select all

F12::
	olApp := ComObjActive("Outlook.Application")
	try
		olItem := olApp.ActiveWindow.CurrentItem
	catch
		olItem := olApp.ActiveExplorer.Selection.Item(1)
	if (olItem.Class = 43)
		olMailItem := olItem
	else
	{
		MsgBox Mail Item Not Current or Selected
		return
	}
	olReplyAllItem := olMailItem.ReplyAll
	olReplyAllItem.Display
return
This is a little more robust than the most basic example. The main point being you need to have an email and then do ReplyAll to it.

This code first checks to see if you currently have an item open, if not if an item is selected. Then it checks to make sure it is an email item and not a contact or some other kind of item. Then does the ReplyAll and Displays it.

Before or after the Display you can do any setting of To:, CC:, Body, Attachments, etc. The same as lots of examples out there about setting properties in a new email.

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
ThiefUK
Posts: 19
Joined: 25 Jul 2017, 10:23

Re: Outlook M.Reply Help

15 Feb 2018, 09:02

That's fantastic and worked perfectly - but there is a problem with adding a :

olReplyAllItem.body :=

To the script, as this replaces the whole thread.

Is there a way to keep the thread I'm replying to and add a reply as I would a normal 'reply' email?

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

Re: Outlook M.Reply Help

15 Feb 2018, 15:25

ThiefUK wrote:That's fantastic and worked perfectly - but there is a problem with adding a :

olReplyAllItem.body :=

To the script, as this replaces the whole thread.

Is there a way to keep the thread I'm replying to and add a reply as I would a normal 'reply' email?

Thanks again,
You just need to put the existing email body back in when you change the body:
olReplyAllItem.Body := "New Stuff to Add Before Existing Stuff" olReplyAllItem.Body

Below is an example using HTML as HTML emails are the default for most people as it allows pretty formatting.

Code: Select all

F12::
	olApp := ComObjActive("Outlook.Application")
	try
		olItem := olApp.ActiveWindow.CurrentItem
	catch
		olItem := olApp.ActiveExplorer.Selection.Item(1)
	if (olItem.Class = 43)
		olMailItem := olItem
	else
	{
		MsgBox Mail Item Not Current or Selected
		return
	}
	olReplyAllItem := olMailItem.ReplyAll
	ReplyHTML =
	(Join
	<h1>Hey everyone,</h1>
	<p>Just wanted to say HI!</p>
	<p>Thanks,<br>FG</p>
	)
	olReplyAllItem.HTMLBody := ReplyHTML olReplyAllItem.HTMLBody 
	olReplyAllItem.Display
return
You can insert pictures, do links, whatever your HTML skills 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
ThiefUK
Posts: 19
Joined: 25 Jul 2017, 10:23

Re: Outlook M.Reply Help

20 Mar 2018, 08:50

Thanks FG!

I'm sorry to bump this - but how would I add attachments?

I've tried quite a few combinations from olReplyAllItem.Attachments.Add, olReplyAllItem.Attachments but they are not recognized, I'm a little unsure how to add a PDF attachment via HTML, can you help?

Thanks!
ThiefUK
Posts: 19
Joined: 25 Jul 2017, 10:23

Re: Outlook M.Reply Help

20 Mar 2018, 09:13

You know what, after 2 weeks of trying and moments after posting this I cracked it... :)

Code here for future users.

Code: Select all

olApp := ComObjActive("Outlook.Application")
	try
		olItem := olApp.ActiveWindow.CurrentItem
	catch
		olItem := olApp.ActiveExplorer.Selection.Item(1)
	if (olItem.Class = 43)
		olMailItem := olItem
	    olByValue := 1

targetattachment = "attachment path"
Hello =  <p>Hello</p>
Sometext =  <p>Sometext</p>
Close =  <p>Close</p>

olReplyAllItem := olMailItem.ReplyAll
olReplyAllItem.HTMLBody := (Hello)(sometext)(close) olReplyAllItem.HTMLBody 
olReplyAllItem.Attachments.Add(targetattachment, olByValue, 1)

olReplyAllItem.Display

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

Re: Outlook M.Reply Help

20 Mar 2018, 12:49

ThiefUK wrote:

Code: Select all

olReplyAllItem.Attachments.Add(targetattachment, olByValue, 1)
For most cases you don't even need to bother with the other parameters after the file name.
olReplyAllItem.Attachments.Add(targetattachment)

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 172 guests