Microsoft Office Forums Need a macro for Outlook 2013 to permanently delete selected message

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-31-2017, 06:27 PM
RetiredCHE RetiredCHE is offline Need a macro for Outlook 2013 to permanently delete selected message Windows 10 Need a macro for Outlook 2013 to permanently delete selected message Office 2013
Novice
Need a macro for Outlook 2013 to permanently delete selected message
 
Join Date: Jun 2016
Location: Alabaster, AL
Posts: 24
RetiredCHE is on a distinguished road
Unhappy Need a macro for Outlook 2013 to permanently delete selected message


I have tried 4 different macros found from web searches to permanently delete a mail item, but none of them worked for me at all. They either did nothing or gave runtime errors.

I have a Quick Step that I can use, but would prefer a macro that I can assign to the QAT. The Outlook VBA online reference and object browser are very close to useless to me. And I haven't been able to find much in the way of books for VBA in Outlook 2013.

Does anyone have code that works in 2013, and/or the name of a good book for 2013 VBA? Any help is greatly appreciated!
Reply With Quote
  #2  
Old 12-31-2017, 10:46 PM
macropod's Avatar
macropod macropod is offline Need a macro for Outlook 2013 to permanently delete selected message Windows 7 64bit Need a macro for Outlook 2013 to permanently delete selected message Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 19,544
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

Have you tried using Shift-Delete? No macros required.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 01-01-2018, 06:22 AM
RetiredCHE RetiredCHE is offline Need a macro for Outlook 2013 to permanently delete selected message Windows 10 Need a macro for Outlook 2013 to permanently delete selected message Office 2013
Novice
Need a macro for Outlook 2013 to permanently delete selected message
 
Join Date: Jun 2016
Location: Alabaster, AL
Posts: 24
RetiredCHE is on a distinguished road
Default

I know about Shift-Delete, and I have a Quick Step item to do a Permanent Delete, but was looking for a macro solution to add to my Quick Access Toolbar. But thanks anyway Paul.
Reply With Quote
  #4  
Old 01-01-2018, 08:17 AM
gmayor's Avatar
gmayor gmayor is offline Need a macro for Outlook 2013 to permanently delete selected message Windows 10 Need a macro for Outlook 2013 to permanently delete selected message Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,906
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

You can delete an item from a folder with VBA, but it then goes into the Deleted items folder, so you need to delete it from there also. This is easy to do if there is nothing in the deleted items folder, or if the deleted item is the latest item in the deleted folder. If not you are going to have to search for it e.g. as follows.

Code:
Sub DeleteSelectedItem()
'Graham Mayor - http://www.gmayor.com - Last updated - 01 Jan 2018 
Dim olItem As Object
Dim lngDel As Long
Dim strSubject As String
Dim strDate As String
Dim objDeletedFolder As Folder
    Set objDeletedFolder = Session.GetDefaultFolder(olFolderDeletedItems)
    On Error Resume Next
    Set olItem = ActiveExplorer.Selection.Item(1)
    strSubject = olItem.Subject
    strDate = olItem.CreationTime
    olItem.Delete
    For lngDel = objDeletedFolder.Items.Count To 1 Step -1
        With objDeletedFolder.Items(lngDel)
            If .Subject = strSubject And .CreationTime = strDate Then
                objDeletedFolder.Items(lngDel).Delete
                Exit For
            End If
        End With
    Next lngDel
lbl_Exit:
    Set objDeletedFolder = Nothing
    Set olItem = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 01-02-2018, 11:07 AM
RetiredCHE RetiredCHE is offline Need a macro for Outlook 2013 to permanently delete selected message Windows 10 Need a macro for Outlook 2013 to permanently delete selected message Office 2013
Novice
Need a macro for Outlook 2013 to permanently delete selected message
 
Join Date: Jun 2016
Location: Alabaster, AL
Posts: 24
RetiredCHE is on a distinguished road
Default Thanks

Thanks, Graham. This code should work just fine. I do find it interesting that there appears to be no way in a single "command" in VBA to permanently delete an item, yet there is such an action available in both rules and Quick Steps.

Happy New Year!
Alan (molechaser)
Reply With Quote
Reply

Tags
2013, delete, vba

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to permanently delete emails out of trash Andoheb Outlook 0 12-22-2015 05:18 AM
Outlook 2013/Outlook.com issue: mail won't delete in bulk, continually disconnects davidvkimball Outlook 0 04-28-2014 11:58 AM
Need a macro for Outlook 2013 to permanently delete selected message Macro Delete Selected Text smonczka Word VBA 2 11-05-2011 03:18 AM
delete email message via blackberry and have it delete on my pop3 and my outlook Iamthestorm Outlook 2 10-28-2010 12:21 AM
Delete files permanently rec Word 2 08-05-2010 01:12 PM


All times are GMT -7. The time now is 07:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft