为什么Outlook更新16.0.9126.2259之后找不到pst中的文件夹?

时间:2018-07-23 11:07:28

标签: outlook outlook-vba outlook-2016

最近几年,我一直在将VBA宏用于Outlook。

它将电子邮件移动到pst文件中的指定文件夹。

由于Outlook更新(16.0.9126.2259)MoveToFolder无效。

编程中的错误处理消息正确生成。

  

找不到目标文件夹!

Sub MoveTomyfolder()
On Error Resume Next

Dim NS As Outlook.NameSpace
Dim moveToFolder As Outlook.MAPIFolder
Dim objItem As Outlook.MailItem

Set NS = Application.GetNamespace("MAPI")

'Define path to the target folder


Set moveToFolder = NS.Folders("Market").Folders("Mails").Folders(".Reports").Folders("myfolder")


If Application.ActiveExplorer.Selection.Count = 0 Then
   MsgBox ("No item selected")
   Exit Sub
End If

If moveToFolder Is Nothing Then
   MsgBox "Target folder not found!", vbOKOnly + vbExclamation, "Move Macro Error"
End If

For Each objItem In Application.ActiveExplorer.Selection
   If moveToFolder.DefaultItemType = olMailItem Then
      If objItem.Class = olMail Then
        If MsgBox("Move to: " & moveToFolder, vbYesNo) = vbNo Then Exit Sub
         objItem.Move moveToFolder
      End If
  End If
Next


Set objItem = Nothing
Set moveToFolder = Nothing
Set NS = Nothing

End Sub

0 个答案:

没有答案