Advertisement
gn4711

Outlook Remove Attachments

Dec 9th, 2012
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub remove_attachments()
  2.  
  3.     Dim app As Outlook.Application
  4.     Set app = CreateObject("Outlook.Application")
  5.    
  6.     Dim ns As Outlook.NameSpace
  7.     Set ns = app.GetNamespace("MAPI")
  8.     ns.Logon
  9.  
  10.     Dim pst As Outlook.MAPIFolder
  11.     Set pst = ns.Folders("Outlook Archiv - Work Old")
  12.    
  13.     Dim root As Outlook.MAPIFolder
  14.     Set root = pst.Folders("_old")
  15.    
  16.     Call remove_attachments_rec(root)
  17.     Beep
  18.    
  19. End Sub
  20.    
  21. Sub remove_attachments_rec(root As Outlook.MAPIFolder)
  22.  
  23.     Dim subFolder As Outlook.MAPIFolder
  24.     For Each subFolder In root.Folders
  25.         Call remove_attachments_rec(subFolder)
  26.     Next
  27.  
  28.     Dim item As Outlook.MailItem
  29.     Dim atts As Outlook.Attachments
  30.     Dim obj As Object
  31.     For Each obj In root.Items
  32.         If TypeName(obj) = "MailItem" Then
  33.             Set item = obj
  34.             Set atts = item.Attachments
  35.             If atts.Count > 0 Then
  36.                 While atts.Count > 0
  37.                     atts(1).Delete
  38.                 Wend
  39.                 item.Save
  40.             End If
  41.         End If
  42.     Next
  43.  
  44. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement