-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathOutlook COM loop through Folders.ahk
52 lines (43 loc) · 1.6 KB
/
Outlook COM loop through Folders.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
; Link: https://www.autohotkey.com/boards/viewtopic.php?t=61520#p260796
; Author:
; Date:
; for: AHK_L
/*
*/
; Adapted from COM Object reference "Outlook.Application"
; https://autohotkey.com/board/topic/56987-com-object-reference-autohotkey-v11/page-11#457708
olApp := ComObjActive("Outlook.Application")
olTestFolder := olApp.Session.Folders("[email protected]").Folders.Item("Test")
MsgBox % olLoopFolder(olTestFolder)
ExitApp
olLoopFolder(olFolder) {
s := "Folder: " olFolder.Name "`r`n"
for olItem in olFolder.Items
s .= A_Index ">" olItem.Subject "`r`n"
for olSubFolder in olFolder.Folders
s .= "`r`n" olLoopFolder(olSubFolder)
return s
}
; Minor modification. This version shows the folder "path"
olLoopFolderPath(olFolder, olFolderPath:="") {
s := "Folder: " olFolderPath olFolder.Name "`r`n"
for olItem in olFolder.Items
s .= A_Index ">" olItem.Subject "`r`n"
for olSubFolder in olFolder.Folders
s .= "`r`n" olLoopFolder(olSubFolder, olFolderPath olFolder.Name "\")
return s
}
; This version sorts the items and adds indentation.
olLoopFolderSort(olFolder, olFolderPath:="", Depth:=0) {
Indent := Format("{:" Depth "}", "")
s := Indent "Folder: " olFolderPath olFolder.Name "`r`n"
for olItem in olSortItems(olFolder.Items)
s .= Indent A_Index ">" olItem.Subject "`r`n"
for olSubFolder in olFolder.Folders
s .= "`r`n" olLoopFolderSort(olSubFolder, olFolderPath olFolder.Name "\", Depth + 8)
return s
}
olSortItems(olMailItems, Property:="[Received]", Descending:=true){
olMailItems.Sort(Property, Descending)
return olMailItems
}