VBA script fail after Office 365 update

D.Moore

Senior Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Dear Diane,

After all update since 12730.20236 (including the latest one), this code not running anymore (though it was working perfectly in the last 2 years). I tried to debug it, and it seems, that can not resolve the shared mailbox (though nothing changed on the mailbox and if I restore a previous version of office from backup prior to 12730.20236, resolve it perfectly).

May I ask if you are aware of any change on resolving shared mailboxes since 12730.20236 ?

Maybe this has something to do with it ? :

https://support.microsoft.com/en-us...s-impacted-april-2020-office-security-updates

Many many thanks,

Moore

Code:
        Set objOwnerDELETE = objNS.CreateRecipient(email)
        objOwnerDELETE.Resolve

        If objOwnerDELETE.Resolved Then

            Set objSourceFolderMAILBOX = objNS.GetSharedDefaultFolder(objOwnerDELETE, olFolderInbox)
            Set objDeletedItems = objSourceFolderMAILBOX
            Set objDeletedItems = objDeletedItems.Parent.Folders("Deleted Items")
            Set objItems = objDeletedItems.Items

            For i = objItems.Count To 1 Step -1
               
                objItems.Item(i).Delete

            Next

            Set objFolders = objDeletedItems.Folders

            For i = objFolders.Count To 1 Step -1

                objFolders.Item(i).Delete

            Next

            Set objDeletedItems = Nothing
            Set objFolders = Nothing
            Set objItems = Nothing

        End If
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I use this in a app start macro and it works - it's used with an itemadd macro. The only time i have problems is if there are connection problems.

Code:
  Set objOwner = objNS.CreateRecipient("accounts@slipstick.com")
    objOwner.Resolve

 If objOwner.Resolved Then
 '  MsgBox objOwner.Name
 Set accountsMailbox = objNS.GetSharedDefaultFolder(objOwner, olFolderInbox)
 End If
 Set accountsInboxItems = accountsMailbox.Items
The changes apply to object libraries (Tools > References) , not to this.
 

D.Moore

Senior Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
You right, as always! I accidentally placed the debug MsgBox to the wrong place. The problem actually is with my For cycle.

When objItems.Count = 0, so i = 0 , so nothing to delete, then its stuck int the for cycle.

Strange why, as it is always worked till now.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
That is weird if it worked before. But the logic is messed up when its 0.
For i = 0 To 1 Step -1

For attachments, I count first and see if greater than 0
lngCount = objAttachments.Count
If lngCount > 0 Then


I have two empty deleted items macros here - Empty Multiple Deleted Items Folders using a Macro - one uses commands, one deleted older items.
 

D.Moore

Senior Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Thank you for your reply!

I had added the deleted items macro into Application_Startup, as I would like to empty the deleted folders when outlook starts up. It works perfecty, BUT for some reason, I creates a strange effect in outlook. Whatever folder I click on, its get cleared, visually. I made a short video about it, and attached it. Could you be so kind and help me why it is, and how to correct it ? BIG thank you in advance!!

Code:
Private Sub Application_Startup()

'Empty ALL mailboxes Deleted folders - START
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim objExpl As Outlook.Explorer
Dim mboxCount As Long
Dim i As Long
Dim deletedItemsFolder As Outlook.Folder
 
    Set olApp = Application
    Set olNS = olApp.GetNamespace("MAPI")
    Set objExpl = olApp.ActiveExplorer
 
    mboxCount = olNS.Folders.Count
    For i = 1 To mboxCount

    On Error Resume Next
    Set deletedItemsFolder = olNS.Folders(i).Folders("Deleted Items")
    
    If Err = 0 Then
        On Error GoTo 0
        objExpl.SelectFolder deletedItemsFolder
        objExpl.CommandBars.ExecuteMso ("EmptyFolder")
    End If
    
    Next i
 
objExpl.SelectFolder olNS.GetDefaultFolder(olFolderInbox)
'Empty ALL mailboxes Deleted folders - FINISHED

End Sub
 

Attachments

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Comment out the last line where it goes back to the inbox, see if that makes a difference.

It looks like the view is goofy as the item count in the lower left doesn't change. Try resetting the view.
 

D.Moore

Senior Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
Comment out the last line where it goes back to the inbox, see if that makes a difference.

It looks like the view is goofy as the item count in the lower left doesn't change. Try resetting the view.
I tried, but thats did not solve the problem. I also reset the view, but this problem only exist, when the code added, if not, there is no problem. Strange.
 

D.Moore

Senior Member
Outlook version
Outlook 2016 64 bit
Email Account
Office 365 Exchange
I found a work around, adding the script into a schedule, eliminated this strange problem. Thank you !
 
Thread starter Similar threads Forum Replies Date
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
N VBA Script to Open highlighted e-mail and Edit Message Outlook VBA and Custom Forms 5
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
Peter H Williams Enable script containing VBA Outlook VBA and Custom Forms 12
R VBA Script Quick Parts Using Outlook 1
Q VBA Script to move item in secondary mailbox Outlook VBA and Custom Forms 2
N VBA Script to Send Automatic Emails from Outlook 2010 Outlook VBA and Custom Forms 1
O modify vba to run it as script rule Outlook VBA and Custom Forms 8
P How many subs can run in one outlook VBA script Using Outlook 5
J Email Parsing VBA Script for Outlook - NEEDED Outlook VBA and Custom Forms 7
P Vba script including macro appears in rules but wont run Outlook VBA and Custom Forms 6
R Adding vba to script list Outlook VBA and Custom Forms 4
F VBA script to highlight specific words Outlook VBA and Custom Forms 1
D VBA Script to extract text matching specific criteria Outlook VBA and Custom Forms 1
D VBA Script (Ask to where to save send mail) Outlook VBA and Custom Forms 1
M VBA script to allow mail merges of distribution groups? Using Outlook 7
D VBA script to auto download attachments and rename file according to subject line Outlook VBA and Custom Forms 23
Hudas Outlook VBA script reverting back to previous changes Outlook VBA and Custom Forms 2
J Outlook 2007 Rules & VBA: How to run a script on a report message (ReportItem) Using Outlook 14
V "Accept + Send the Response now", VBA script? Using Outlook 1
R Addins4Outlook TagIt! addin script or VBA module? Using Outlook 2
S Outlook VBA rule script to process both MailItem and MeetingItem Using Outlook 0
A VBA Script to Forward Spam to AntiSpam Provider Using "Blank" Form Outlook VBA and Custom Forms 2
L Limit VBA Script to one Outlook account Using Outlook 1
L Macro/VBA to Reply All, with the original attachments Outlook VBA and Custom Forms 2
L VBA unknown character Outlook VBA and Custom Forms 2
G Move tasks up/down todo list by VBA Outlook VBA and Custom Forms 1
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
K Use VBA to find Sender and Recipient from Microsfot 365 Journaled Email Items Outlook VBA and Custom Forms 3
J Want to learn VBA Macros for Outlook. What book can you recommend? Outlook VBA and Custom Forms 2
F VBA code to dock Styles whenever I write or edit an email Outlook VBA and Custom Forms 0
C VBA to prompt for Sent folder destination Outlook VBA and Custom Forms 3
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1
B Change Font and Font size using VBA Outlook VBA and Custom Forms 9
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
R Limiting length of saved attachment in VBA Outlook VBA and Custom Forms 2
S Skype for business meeting vba code Outlook VBA and Custom Forms 1
C How to use VBA to show only items x days old or more Outlook VBA and Custom Forms 1
B VBA to convert email to task, insert text of email in task notes, and attach copy of original email Outlook VBA and Custom Forms 4
D Outlook VBA error extracting property data from GetRules collection Outlook VBA and Custom Forms 10
S Reference Custom Fields with VBA Outlook VBA and Custom Forms 2
PGSystemTester VBA To Change AppointmentItem.BusyStatus From MeetingItem Before Send Using Outlook 0
A VBA macro for 15 second loop in send and received just for 1 specific mailbox Outlook VBA and Custom Forms 1
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
G VBA Macro Calendar Printing Assistant 4
R Help Revising VBA macro to delete email over different time span Outlook VBA and Custom Forms 0
B VBA to Collapse Task Folder Groups Outlook VBA and Custom Forms 1
R Expand VBA Permanent Delete Code Outlook VBA and Custom Forms 6
shrydvd vba to secure zip attachments Outlook VBA and Custom Forms 3
Similar threads


















































Top