我在Outlook中创建了一系列宏来处理从支持客户那里收到的电子邮件。 基本上有3个宏:
一切正常,但是由于几个星期以来,副本也发送到了删除文件夹,在某些情况下,它会直接转到该删除文件夹,而没有副本到预期的副本。
除使用Exchange服务器的个人邮箱外,宏使用的邮箱是我们在Outlook中拥有的IMAP邮箱。 我不明白为什么会突然这样做。
Option Explicit
Sub AddFileNumber()
'add initials to the email header
Dim myolApp As Outlook.Application
Dim aItem As Object
Set myolApp = CreateObject("Outlook.Application")
Set aItem = myolApp.ActiveExplorer.Selection.Item(1)
Dim iItemsUpdated As Integer
Dim strTemp As String
Dim strFilenum As Variant
strFilenum = "(DR) - "
If strFilenum = False Then Exit Sub
If strFilenum = "" Then Exit Sub
strTemp = "" & strFilenum & "" & aItem.Subject
aItem.Subject = strTemp
aItem.Save
End Sub
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
Sub MasterMacro()
'add the initials and move the email to the selected folder
Call Request.AddFileNumber
Call Request.MoveSelectedMessagesToFolder
End Sub
Option Explicit
Sub UpdateRequest()
' adds $UPDATE TO REQUEST$ and initials to the email header
Dim myolApp As Outlook.Application
Dim aItem As Object
Set myolApp = CreateObject("Outlook.Application")
Set aItem = myolApp.ActiveExplorer.Selection.Item(1)
Dim iItemsUpdated As Integer
Dim strTemp As String
Dim strFilenum As Variant
strFilenum = "$UPDATE TO REQUEST$ (DR) - "
If strFilenum = False Then Exit Sub
If strFilenum = "" Then Exit Sub
strTemp = "" & strFilenum & "" & aItem.Subject
aItem.Subject = strTemp
aItem.Save
End Sub
Option Explicit
Sub MoveSelectedMessagesToFolder()
On Error Resume Next
Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.MailItem
Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objFolder = objNS.Folders.Item("DOJ Helpdesk") _
.Folders.Item("Inbox").Folders.Item("REQUESTS")
If objFolder Is Nothing Then
MsgBox "This folder doesn't exist!", vbOKOnly _
+ vbExclamation, "INVALID FOLDER"
End If
If Application.ActiveExplorer.Selection.Count = 0 Then
Exit Sub
End If
For Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
objItem.Move objFolder
objItem.UnRead = True
objItem.Save
End If
End If
Next
End Sub
Sub MasterUpdate()
' call both modules above
Call Request.UpdateRequest
Call Request.MoveSelectedMessagesToFolder
End Sub