david_Johnson_CR
Member
- 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
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