This currently works perfect when you have the new mail open in a separate message window, but fails when the new mail is embedded in the main Outlook window (you could descripe this as "not popped out").
So the line oItem := ComObjActive("Outlook.Application").ActiveExplorer.Selection.Item(1) fails to connect to the active mailItem.
Code: Select all
F12::
{
; Create shortcutmenu for recent documents.
File_List :=""
loop, Files, E:\users\DGE1507\PLOT\*
{
currentTime := A_now
EnvSub, currentTime, %A_LoopFileTimeModified%, Hours
File_List .= currentTime "`t" A_Loopfilefullpath "`t" A_LoopFileName "`n"
}
Sort, File_List, N
Menu, mFilesNew, Add,
Menu, mFilesNew, DeleteAll
loop, Parse, File_list, `n
{
; only show the 10 last items
If (A_index=11){
break
}
if (A_Loopfield=""){
continue
}
arrFile := StrSplit(A_Loopfield, "`t")
BoundGivePar := Func("Outlook_AddAttachments").Bind(arrFile.2)
Menu, mFilesNew, Add, % arrFile.3, % BoundGivePar
}
Menu, mFilesNew, Show
return
}
Outlook_AddAttachments(File){
WinGetTitle, WinTitle, A
if InStr(WinTitle, "- Message"){
oItem := ComObjActive("Outlook.Application").ActiveWindow.CurrentItem ; connects to open message if separate window
}
Else{
; Connect to outlook mail but this does not work...
oItem := ComObjActive("Outlook.Application").ActiveExplorer.Selection.Item(1)
}
Subject := oItem.subject
oItem.Attachments.Add(File)
return
}