-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThisOutlookSession.cls
236 lines (188 loc) · 7.07 KB
/
ThisOutlookSession.cls
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
Dim gEntryId As String
Function GetCurrentItem() As Object
Dim objApp As Outlook.Application
Set objApp = Application
On Error Resume Next
Select Case TypeName(objApp.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = _
objApp.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = _
objApp.ActiveInspector.CurrentItem
Case Else
End Select
End Function
Public Sub MarkMailForMeeting()
Dim myOlApp As Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim mySel As Outlook.Selection
Dim myItem As Outlook.MailItem
Set mySel = Application.ActiveExplorer.Selection
Set myItem = mySel.Item(1)
gEntryId = myItem.EntryID
End Sub
Public Sub AttachItem()
'Attach MailItem from gEntryId into the currently selected Appointment
Dim olApp As Outlook.Application
Dim olApt As Outlook.AppointmentItem
Dim olMail As Outlook.MailItem
Dim olMailCopy As Outlook.MailItem
Dim myCopiedMessage As Outlook.MailItem
Dim olNS As Outlook.NameSpace
Set olApp = New Outlook.Application
' Set olApt = olApp.CreateItem(olAppointmentItem)
Set olNS = olApp.GetNamespace("MAPI")
olNS.Logon
Set olMail = olNS.GetItemFromID(gEntryId)
Set olMailCopy = olMail.Copy
Dim olSel As Outlook.Selection
Set olSel = Application.ActiveExplorer.Selection
olSel.Item(1).Attachments.Add olMailCopy, olByValue
' olItem.Attachments.Add olMailCopy, olByValue
olSel.Item(1).Save
olMailCopy.Delete
End Sub
Public Sub ToDo_WaitingFor()
tFolder = "Waiting For"
CreateTasks (tFolder)
End Sub
Public Sub ToDo_Next()
tFolder = "Next"
CreateTasks (tFolder)
End Sub
Public Sub ToDo_SmallP()
tFolder = "Small"
CreateTasks (tFolder)
End Sub
Public Sub ToDo_LargeP()
tFolder = "Large"
CreateTasks (tFolder)
End Sub
Public Sub ToDo_Later()
tFolder = "Later"
CreateTasks (tFolder)
End Sub
Private Sub CreateTasks(tFolder As String)
Dim Ns As Outlook.NameSpace
Dim olTask As Outlook.TaskItem
Dim Item As Outlook.MailItem
Dim taskFolders As Outlook.Folders
Dim taskFolder As Outlook.Folder
Set Ns = Application.GetNamespace("MAPI")
Set Item = Application.ActiveExplorer.Selection.Item(1)
Set taskFolders = Ns.GetDefaultFolder(olFolderTasks).Folders
For Each Folder In taskFolders
If InStr(1, Folder.Name, tFolder, 1) > 0 Then
Set taskFolder = Folder
Exit For
End If
Next
Item.Move taskFolder.Parent.Parent.Folders("Archive")
Set olTask = taskFolder.Items.Add(olTaskItem)
With olTask
.Subject = Item.Subject
.Attachments.Add Item
If tFolder = "Next" Then
.ReminderSet = True
.ReminderTime = Now + TimeSerial(0, 5, 0)
End If
.Body = Item.Body
.RTFBody = Item.RTFBody
.Save
End With
Set Ns = Nothing
End Sub
Public Sub SaveAttachment()
Dim objItem As Outlook.MailItem
Dim objAttach As Outlook.Attachment
Dim dateFormat As String
dateFormat = Format(Now, "yyyy-mm-dd H-mm")
Set objItem = GetCurrentItem()
Const strAttachmentPath = "C:\Users\juergen.richert\OneDrive - BioNTech SE\Attachments\"
For i = 1 To objItem.Attachments.Count
Set objAttach = objItem.Attachments(i)
objAttach.SaveAsFile strAttachmentPath & dateFormat & " " & objAttach.FileName
Next
Set objItem = Nothing
Set objMail = Nothing
End Sub
Public Sub BulkDeleteAppointments()
Dim oAppt As Object
Dim itemsToDelete As Object
Dim cancelMsg As String
' did user select date range or individual items?
If Application.ActiveExplorer.Selection.Count > 0 Then
Set itemsToDelete = Application.ActiveExplorer.Selection
ElseIf (datRange.startDate <> datRange.datNull) And (datRange.endDate <> datRange.datNull) Then
MsgBox "Nothing selected.", vbOKOnly, "Bulk delete"
Exit Sub
End If
' only proceed if items are selected by now, either automatically or manually
If itemsToDelete.Count > 0 Then
' What shall we send as message?
cancelMsg = InputBox(Prompt:="Your cancel message please. There will be no confirmation.", _
Title:="ENTER YOUR MESSAGE", Default:="I will be on vacation.")
If (cancelMsg <> "") Then
For Each oAppt In itemsToDelete
DeleteItemWithDefaultMessage oAppt, cancelMsg
Next oAppt
End If
End If
End Sub
Private Sub DeleteItemWithDefaultMessage(oItem, cancelMsg)
Dim strMessageClass As String
Dim oAppointItem As Outlook.AppointmentItem
Dim myMtg As Outlook.MeetingItem
strMessageClass = oItem.MessageClass
If (strMessageClass = "IPM.Appointment") Then ' Only operate on Calendar Entry.
Set oAppointItem = oItem
If oAppointItem.Organizer = Outlook.Session.CurrentUser Then ' If this is my own meeting
oAppointItem.MeetingStatus = olMeetingCanceled
oAppointItem.Body = cancelMsg
oAppointItem.Save
oAppointItem.Send
Else ' If I was invited to this meeting
Set myMtg = oAppointItem.Respond(olMeetingDeclined, True, False)
If Not myMtg Is Nothing Then
myMtg.Body = cancelMsg
myMtg.Send
End If
End If
End If
End Sub
Public Sub BulkDeleteAppointments_noMessage()
Dim oAppt As Object
Dim itemsToDelete As Object
Dim cancelMsg As String
' did user select date range or individual items?
If Application.ActiveExplorer.Selection.Count > 0 Then
Set itemsToDelete = Application.ActiveExplorer.Selection
ElseIf (datRange.startDate <> datRange.datNull) And (datRange.endDate <> datRange.datNull) Then
MsgBox "Nothing selected.", vbOKOnly, "Bulk delete"
Exit Sub
End If
' only proceed if items are selected by now, either automatically or manually
If itemsToDelete.Count > 0 Then
For Each oAppt In itemsToDelete
DeleteItemWithoutMessage oAppt
Next oAppt
End If
End Sub
Private Sub DeleteItemWithoutMessage(oItem)
Dim strMessageClass As String
Dim oAppointItem As Outlook.AppointmentItem
Dim myMtg As Outlook.MeetingItem
strMessageClass = oItem.MessageClass
If (strMessageClass = "IPM.Appointment") Then ' Only operate on Calendar Entry.
Set oAppointItem = oItem
If oAppointItem.Organizer = Outlook.Session.CurrentUser Then ' If this is my own meeting
' Do nothing
Else ' If I was invited to this meeting
Set myMtg = oAppointItem.Respond(olMeetingDeclined, True, False)
If Not myMtg Is Nothing Then
myMtg.Save
End If
End If
End If
End Sub