Delete Emails from Senders in Shared Mailbox

Status
Not open for further replies.
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Greetings,

I'm having a little trouble with some code. I'm trying to delete emails from certain addresses from a shared mailbox. I'm getting a Block Variable not set error. I'm marrying two sets of code to make this work (not work). Any help you could provide would be greatly appreciated. I've tried searching but I didn't see anything similar enough that I could understand how to use it.

Thanks!
David

Code:
Sub DeleteItems()

    Dim objOutlook As Outlook.Application   
    Dim myNameSpace As Outlook.NameSpace
    Dim objVariant As Variant
    Dim myInbox As Outlook.Folder
    Dim myItems As Outlook.Items
    Dim myItem As Object
    Dim inboxSourceFolder As Outlook.MAPIFolder
    dim objOwner as outlook.recipient

'### Get Shared
    
'THE LINE BELOW IS THROWING THE ERROR
    Set objOwner = mynamespace.CreateRecipient("tdem")
    objOwner.Resolve
    Set inboxSourceFolder = mynamespace.GetSharedDefaultFolder(objOwner, olFolderInbox)
 
    Set myNameSpace = Application.GetNamespace("MAPI")
    Set myInbox = inboxSourceFolder.Folders("internalemailonly")
    Set myItems = myInbox.Items

    '// loop for each sender
    Set myItem = myItems.Find("[SenderName] = no-reply@emgrantspro.com")
    While TypeName(myItem) <> "Nothing"
        myItem.Delete
        Set myItem = myItems.FindNext
    Wend

    '// Loop Next Sender
    'Set myItem = myItems.Find("[SenderName] = 'Tom Hanks'")
    'While TypeName(myItem) <> "Nothing"
    '    myItem.Delete
    '    Set myItem = myItems.FindNext
    'Wend

    'Set myItem = myItems.Find("[SenderName] = 'Alisa Milano'")
    'While TypeName(myItem) <> "Nothing"
    '    myItem.Delete
    '    Set myItem = myItems.FindNext
    'Wend

    ' More here
End Sub
 
Status
Not open for further replies.
Thread starter Similar threads Forum Replies Date
J Moved many emails to Outlook external folder, need to delete on Gmail server Using Outlook 13
N VBA to delete duplicates by message-id on common pst for 2 or more emails Outlook VBA and Custom Forms 0
S How can I delete all copies of a given companies logo graphic from all my emails at once? Using Outlook 3
O Delete duplicate emails - subscription notifications Using Outlook 5
J Delete old emails Exchange Server Administration 1
T Delete Emails from search results Outlook VBA and Custom Forms 1
B How to 'really' delete IMAP emails? Using Outlook 6
D Delete selected text from incoming emails Outlook VBA and Custom Forms 25
M Cannot Delete Emails from IMAP inbox Using Outlook 4
T How to send to spam/delete emails with specific heading? Using Outlook 3
J Delete emails older than Using Outlook 1
F Outlook 2010 unable to delete emails from scanner Using Outlook 1
A I have a roaming profile and when I delete emails from one computer Using Outlook 1
N Delete non working emails from contacts Outlook Wishlist 1
A rule to move emails to a folder then want to delete them from that folder 2010 Using Outlook 5
D Outlook 2010 registry hack - delete emails - Google Apps Using Outlook 0
P PST reached maximum size- cant delete emails to slim it down Using Outlook 5
M DELETE EMAILS IN OUTLOOK 2010__ Using Outlook 2
I My "DELETE" key does not work when I am in my Outlook email but works when in other emails such as G Using Outlook 2
T After updating Exchange 2010 from RTM to SP1, OWA clients cannot move or delete emails Using Outlook 4
N Error: 8004102A - Unable to delete emails properly Using Outlook 1
B OWA Full Mailbox---Can't Delete Emails Using Outlook 3
N I use the keyboard to delete emails and every so often the focus changes to the reminders window and I delete reminders by mistake Using Outlook 1
T unable to move or delete emails in IMAP folder Using Outlook 2
Z Error code 0x840ccc33__Cannot delete emails from INBOX of MSN Mail - Inbox- MSN Explorer when viewin Using Outlook 2
J I cannot delete emails and I am over my storage limit. I have tried shift+delete and attempted to mo Using Outlook 1
T Deleted emails do not appear in Delete folder. Using Outlook 1
T Delete all emails but not account Exchange 2010 Exchange Server Administration 5
R Losing emails in my main server account, Charter Communications, when I delete emails in the Outlook Using Outlook 2
D Can't File away or delete some emails. Using Outlook 1
D My Mail box is full and will not stay open and give me access to delete emails can you help__ Using Outlook 2
O I have 5 emails stuck in the outbox that are probably too large to be sent, but I can not delete them. How do I delete them and start over sending th Using Outlook 2
T delete many emails Exchange Server Administration 2
B How do I delete all emails in an inbox, all at once, without deleting the inbox itself? Using Outlook 2
G outlook 2010-delete open emails Using Outlook 4
K Outlook 2003SP3 users connecting to Exchange 2010RU3 cannot delete emails Exchange Server Administration 5
J To delete the draft email Using Outlook 0
W Recurrence: delete older occurrences / change earliest start time Outlook VBA and Custom Forms 0
A Attachments.Delete Outlook VBA and Custom Forms 3
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
M Delete headers in Inline reply Outlook VBA and Custom Forms 5
9 Outlook 2016 How to save an Outlook attachment to a specific folder then delete the email it came from? Using Outlook 1
D after delete mail, open the next one Outlook VBA and Custom Forms 0
F Delete/create/reset Exchange mailbox on Outlook.com Using Outlook.com accounts in Outlook 3
L Email Read and Delete Outlook VBA and Custom Forms 4
H Delete Calendar Entries in Using Outlook 2
R How to delete Facebook Contacts folder in Outlook 365 Using Outlook 7
R VBA Code to permanently delete selected email Outlook VBA and Custom Forms 10
JoeG Appointment Delete/Change Recurrence Outlook VBA and Custom Forms 0
Similar threads


















































Top