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,
Outlook M.Reply Help
Re: Outlook M.Reply Help
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.
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.
- FanaticGuru
- Posts: 1907
- Joined: 30 Sep 2013, 22:25
Re: Outlook M.Reply Help
Here is an example:
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
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 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
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
Re: Outlook M.Reply Help
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,
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,
- FanaticGuru
- Posts: 1907
- Joined: 30 Sep 2013, 22:25
Re: Outlook M.Reply Help
You just need to put the existing email body back in when you change the body: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,
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
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
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
Re: Outlook M.Reply Help
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!
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
You know what, after 2 weeks of trying and moments after posting this I cracked it...
Code here for future users.
Yey!
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
- FanaticGuru
- Posts: 1907
- Joined: 30 Sep 2013, 22:25
Re: Outlook M.Reply Help
For most cases you don't even need to bother with the other parameters after the file name.ThiefUK wrote:Code: Select all
olReplyAllItem.Attachments.Add(targetattachment, olByValue, 1)
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
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
Who is online
Users browsing this forum: Chunjee and 150 guests