使用 VBA 宏将所选电子邮件移动到 Outlook 中的垃圾邮件文件夹

Move Selected Email to Junk E-mail folder in Outlook using VBA Macro

我正在尝试创建一个子程序,当子程序被调用时,它会简单地将所有当前选定的邮件移动到 Outlook 中的默认垃圾文件夹。
我很难找到任何我可以使用的参考资料,非常感谢帮助。

这对你有用

Sub MoveItems()
    Dim myDestFolder As Outlook.Folder
    Set myDestFolder = Application.GetNamespace("MAPI").Folders("youremailaddress").Folders("[Gmail]").Folders("Spam") ' or Junk
    Dim myItem As Object
    Set myItem = GetCurrentItem
    myItem.Move myDestFolder
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
    End Select
    GetCurrentItem.UnRead = False
    Set objApp = Nothing
End Function

我的宏版本:

Public Sub MarkSelectedAsSpam()
    Dim junkFolder As Outlook.Folder
    Set junkFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderJunk)
    Dim email As Object
    For Each email In Application.ActiveExplorer.Selection
        email.Move junkFolder
    Next
End Sub

将选定的电子邮件删除到垃圾文件夹。