Page 1 of 1
Outlook M.Reply Help
Posted: 13 Feb 2018, 11:29
by ThiefUK
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,
Re: Outlook M.Reply Help
Posted: 14 Feb 2018, 09:03
by ThiefUK
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.
Re: Outlook M.Reply Help
Posted: 14 Feb 2018, 13:26
by FanaticGuru
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
Re: Outlook M.Reply Help
Posted: 15 Feb 2018, 09:02
by ThiefUK
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,
Re: Outlook M.Reply Help
Posted: 15 Feb 2018, 15:25
by FanaticGuru
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
Re: Outlook M.Reply Help
Posted: 20 Mar 2018, 08:50
by ThiefUK
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!
Re: Outlook M.Reply Help
Posted: 20 Mar 2018, 09:13
by ThiefUK
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!
Re: Outlook M.Reply Help
Posted: 20 Mar 2018, 12:49
by FanaticGuru
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