Outlook VBA Permanently Delete Old Emails From Shared Mailbox -
i have issue need permanently delete emails shared mailbox older age.
unfortunately, autoarchive function not affect shared mailbox, , every time try run rule this, fails , not take action. i've been having manually clear hundreds of emails mailbox takes absolute age (when have on 300k sitting in there...), fills own deleted items when do.
i versed in excel vba have no clue how outlook likes handle things. i've been searching way have yet find reliable can use annotated teach me.
has else ever had same thing? can't 1 wants this?
edit: i've been chopping random bits of code i've found try , achieve this. have access 6 other shared mailboxes within department. i've been looking @ getshareddefaultfolder function not explained , errors when bodged attempt runs. not sure wants in recipient function, have tried mailbox name , address. ms online resources aren't helpful in case:
edit 2:
i have edited code below. in version overflow error on line intcount = olsharedbox.items.count 1 step -1 since there on 300k emails in box think looking @ right thing not sure of way around it. not possible current number pre-counted figure appears next inbox?
sub deleteoldsharedmail() dim olapp outlook.application dim olns outlook.namespace dim olmailitem outlook.mailitem dim objvariant variant dim lngmoveditems long dim intcount integer dim intdatediff integer dim olsharedbox folder dim mbowner outlook.recipient set olapp = outlook.application set olns = olapp.getnamespace("mapi") set mbowner = olns.createrecipient("mailbox@email.com") set olsharedbox = olns.getshareddefaultfolder(mbowner, olfolderinbox) intcount = olsharedbox.items.count 1 step -1 set objvariant = olsharedbox.items.item(intcount) doevents if objvariant.class = olmail intdatediff = datediff("d", objvariant.senton, now) ' set number of days if intdatediff > 180 objvariant.delete call cleardeletedfolder ' working. change call every 100 emails deleted after first run. 'count # of items moved lngmoveditems = lngmoveditems + 1 ' no need run if statement on rest of mailbox assuming macro runs oldest newest. 'else: goto marker end if end if next ' display number of items moved. marker: msgbox "moved " & lngmoveditems & " messages(s)." end sub
you can use namespace.getshareddefaultfolder method @ inbox delete items. however, if items in folder need full mailbox access mailbox or write permissions on specific folders. in cases need find folders in mailbox if mailbox has been added current outlook profile. can access folders matching store object in namespace.stores (e.g. via store.getdefaultfolder or .getrootfolder, "walk" through folder.folders collections).
regardless, there on way permanently delete email in outlook object model. can delete twice if find again in deleted items folder.
see also: how to: delete items , subfolders in deleted items folder
Comments
Post a Comment