This is probably my most-used hotkey. It copies the text that is selected and then searches in MS Outlook.
Code: Select all
; Microsoft Outlook hotkeys (WinExist)
#IfWinExist, ahk_class rctrl_renwnd32
; Copy the selection and find an exact match (enclosed in quotes with "*" at the end) in Outlook
^F11::OutlookCopyAndSearch()
OutlookCopyAndSearch()
{
static olSearchScopeAllFolders := 1
Clipboard := ""
Send, ^c
ClipWait, 1, 1
if ErrorLevel
return
ComObjActive("Outlook.Application").ActiveExplorer.Search("""" Clipboard "*""", olSearchScopeAllFolders)
; Activate the Outlook window
WinActivate, ahk_class rctrl_renwnd32
; Send Tab to hide the "suggested searches" drop down
ControlSend, RICHEDIT60W1, {Tab}, ahk_class rctrl_renwnd32
}
With an image selected, add a caption and shadow.
Code: Select all
; Microsoft Outlook hotkeys (WinActive)
#IfWinActive ahk_class rctrl_renwnd32
; With an image selected, press F8 to add a caption and shadow
F8::OutlookAddCaptionAndShadow()
OutlookAddCaptionAndShadow()
{
static olExplorer := 34
static olInspector := 35
static wdSelectionInlineShape := 7
static msoShadow25 := 25
; Get the Word Editor Application of the email that is being written
myWindow := ComObjActive("Outlook.Application").ActiveWindow
if (myWindow.Class = olExplorer) ; The main Outlook window
try wdApp := myWindow.ActiveInlineResponseWordEditor.Application
else if (myWindow.Class = olInspector) ; The email is open in its own window
{
; Check if the current item is being edited
if (MyWindow.CurrentItem.Sent = 0)
wdApp := myWindow.WordEditor.Application
}
; Add a shadow and caption to the selected image
if (wdApp.Selection.Type = wdSelectionInlineShape)
{
wdApp.Selection.InlineShapes.Item(1).Shadow.Type := msoShadow25
; .InsertCaption changes the selection, so you can't use .Selection to refer to the image after this
wdApp.Selection.InsertCaption("Figure")
}
}
Code: Select all
F9::OutlookAddAttachment("C:\Test\New Text Document.txt")
OutlookAddAttachment(File)
{
static olExplorer := 34
static olInspector := 35
; Get the email that is being written
myWindow := ComObjActive("Outlook.Application").ActiveWindow
if (myWindow.Class = olExplorer) ; The main Outlook window
olItem := myWindow.ActiveInlineResponse
else if (myWindow.Class = olInspector) ; The email is open in its own window
olItem := myWindow.CurrentItem
; Attach the file
olItem.Attachments.Add(File)
}
Create an email and add a subject, body, and recipients.
Code: Select all
; Example usage
OutlookCreateEmail("This is the subject.", "This is the body.", ["Jane Smith", "Jill Wilson", "example@xyz.com"])
ExitApp
; OutlookCreateEmail
; Subject (String) Email subject.
; Body (String) Email Body.
; Recips (Object) An array containing names or email addresses to add as recipients. Names are attempted to be
; resolved against the Outlook Address Book. Email addresses seem to be resolved as long as they
; are valid. Duplicate email addresses will not be added twice, so you can attempt to resolve the
; name and if that fails you can use the email. (Place names before emails in the array so that
; when the array is enumerated the names are resolved before the email addresses.)
OutlookCreateEmail(Subject, Body, Recips)
{
static olMailItem := 0
try oApp := ComObjActive("Outlook.Application")
catch
{
MsgBox, 0x40, New Email Error, Failed to connect to Outlook.`nOutlook must be running first.
return
}
oMailItem := oApp.CreateItem(olMailItem)
oMailItem.Subject := Subject
oMailItem.Body := Body
; Add each recipient and attempt to resolve it against the Address Book.
Added := {} ; Record added emails to prevent duplicates
for i, Recip in Recips
{
if (Recip = "")
continue
oRecip := oMailItem.Recipients.Add(Recip)
oRecip.Resolve
; Deletes duplicate recipients or ones that are not resolved
if (!oRecip.Resolved) || Added[oRecip.Address]
oRecip.Delete
else
Added[oRecip.Address] := true
}
oMailItem.Display
; Fix paragraph spacing
oParFormat := oMailItem.GetInspector.WordEditor.Range.ParagraphFormat
oParFormat.SpaceBeforeAuto := 0
oParFormat.SpaceAfterAuto := 0
oParFormat.SpaceBefore := 0
oParFormat.SpaceAfter := 0
}
When an Outlook application event is fired this script shows the name of the event and info about the parameters.
Note: Try Outlook Rules before resorting to events.
Code: Select all
#Persistent
olApp := ComObjActive("Outlook.Application")
ComObjConnect(olApp, new Outlook_Events)
return
class Outlook_Events
{
__Call(Event, Args*)
{
EventInfo := ""
for i, val in Args
{
if (Format("{:X}", ComObjType(val)) = 0)
EventInfo .= "Arg#: " i
. "`nNot an object"
. "`nValue: " val "`n`n"
else
EventInfo .= "Arg#: " i
. "`nVarType: " Format("{:X}", ComObjType(val))
. "`nIName: " ComObjType(val, "Name")
. "`nIID: " ComObjType(val, "IID")
. "`nCName: " ComObjType(val, "Class")
. "`nCLSID: " ComObjType(val, "CLSID") "`n`n"
}
MsgBox,, % "Application." Event " - " Args[Args.MaxIndex()].Name, % EventInfo
}
; Define methods here to respond to specific events
; static olFolderInbox := 6
;
; ; Example method fired when new mail is received in the inbox. This will assign the mail item to categories,
; ; mark it as read, and show a MsgBox with the subject.
; NewMailEx(EntryIDCollection, olApp)
; {
; olns := olApp.Session ; Namespace
; olFolder := olns.GetDefaultFolder(Outlook_Events.olFolderInbox) ; Get the Inbox folder
; StoreID := olFolder.StoreID ; Get the StoreID, which is a property of the folder.
; olItem := olns.GetItemFromID(EntryIDCollection, StoreID) ; Get the MailItem object from the entry ID
; olItem.Categories := "Yellow Category, Blue Category" ; Assign categories to the mail item
; olItem.Unread := 0 ; Mark as read
; olItem.Save
; MsgBox % olItem.Subject
; }
}