Hello Alex, thank you for reaching out to the Microsoft Community. I am here to help and provide assistance with any questions or concerns you may have.
I just checked your VBA script and appears to be correct. Once executed, it should move emails from the Trash folder to the Deleted Items folder in Outlook.
In the event that the script is not running, you may want to consider examining the following aspects, just in case:
• Reference Correct Email Account: Verify that you have correctly replaced "@.___" in the line Set olFolder = olNs.Folders("___@___.___").Folders("Deleted Items") with the actual email address associated with the account you want to work with.
• Correct Folder Names: Make sure the folder names "Trash" and "Deleted Items" match the actual folder names in your Outlook mailbox. Folder names are case-sensitive, so ensure that the capitalization is accurate.
• Run the Macro: After updating the script, you need to run the macro manually. Press Alt + F8 in Outlook to open the "Macro" dialog box, select MoveEmailsFromTrashToDeletedItems, and click "Run."
You can also try this script:
Sub MoveEmailsFromTrashToDeletedItems()
Dim olApp As Outlook.Application
Dim olNs As Outlook.Namespace
Dim olFolder As Outlook.Folder
Dim olTrashFolder As Outlook.Folder
Dim olDeletedItemsFolder As Outlook.Folder
Dim olItem As Object
' Create an instance of Outlook
Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
' Set the reference to the mailbox you want to work with
Set olFolder = olNs.GetDefaultFolder(olFolderInbox)
' Set the reference to the Trash folder
Set olTrashFolder = olFolder.Folders("Trash")
' Set the reference to the Deleted Items folder
Set olDeletedItemsFolder = olFolder.Folders("Deleted Items")
' Move each email from Trash to Deleted Items
For Each olItem In olTrashFolder.Items
If TypeOf olItem Is Outlook.MailItem Then
olItem.Move olDeletedItemsFolder
End If
Next olItem
' Clean up
Set olItem = Nothing
Set olDeletedItemsFolder = Nothing
Set olTrashFolder = Nothing
Set olFolder = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub
If the script still does not work, there may be other factors at play. For example, the script could be restricted by security policies or permissions set by your organization's IT department.
I hope these suggestions help! Let me know if you have any other questions or if there is anything else I can do to assist you.