Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item"

Status
Not open for further replies.

aliastral

New Member
Outlook version
Outlook 2019 32-bit
Email Account
IMAP
Hello!

With much help from code snippets I've pieced together from the internet (thanks Slipstick.com!), I've implemented a short macro that fires whenever an email is moved to a different folder in our team's shared mailbox.
I don't dare to say it's anywhere near elegant, but the code works for the most part.

However, on certain 'emails' it throws a run-time error '430' saying that the class does not support automation.
Debugging shows that the error occurs on the following line:

C-like:
Set objMailItem = Application.ActiveExplorer.Selection.Item(1) 'if both above conditions are met, sets objMailitem object as the currently selected item'

Previously, it appeared that this would happen when the user tried to move emails that were not technically emails (e.g. meeting invitations, requests for moderation approval, message read notifications). I added an additional check for the Mailitem.Sent property which seems to have reduced the number of occurrences.
As we only have six users (and some users click away the error without telling me), I've had some trouble pinpointing the exact cause of the issue.

However, I've now also encountered the problem on a regular email message, but only on this specific message.
To try and isolate the issue, I've found the following:
  1. Email was very recently replied to (I replied to it and immediately tried to move it into another folder).
  2. Email cannot be previewed in the viewing pane (Shows the message: "This item cannot be displayed in the reading pane. Open the item to read its contents.").
  3. Email cannot be opened in a new window (Shows the message: "Sorry, we're having trouble opening this item. This could be temporary, but if you see it again you might want to restart Outlook.").

This error stops all macros from running, including a secondary macro I have that sets the .SendUsingAccount and .SendOnBehalfOf for each outgoing message. If needed, I can post the entire VBA module.

Ideally, I'd like to find a way for Outlook to exclude these error causing emails.
Of course, if there are deeper issues with my code, I'd definitely appreciate insight on that as well.

Additional information that might be helpful:
  1. The macro is installed on six computers, and I'd say the error occurrence rate is "infrequent".
  2. The macro seems to work fine for 99% of all email messages.
  3. All six computers have Microsoft Outlook for Microsoft 365 MSO 32bit installed via Microsoft's installer obtained via portal.office.com.
  4. As far as I know, all six computers are on the same Office 365 update ring (my computer is currently on 16.0.12827.20200).

C-like:
Private Sub myOlExp_BeforeItemPaste(ClipboardContent As Variant, ByVal Target As MAPIFolder, Cancel As Boolean)

Dim strRemark As String 'declares string'
Dim strDate As String 'declares string'
Dim strDestination As String 'declares string'
Dim strUser As String 'declares string'

strDestination = Target 'sets strDestination string as item paste target'
strDate = Format(Now, "MM/dd") 'sets strDate string as current day'
strUser = "Justin" 'sets strUser string as current user'

strRemark = "[" & strDate & "] " & strUser & " moved to '" & strDestination & "'" 'combines above three strings into one and adds symbols/text for clarity'

If Application.ActiveExplorer.Selection.Item(1).Class = olMail Then 'checks to see if selection is of olMail class'
    If Application.ActiveExplorer.Selection.Item(1).Sent = True Then 'checks for the mailitem.sent property to ensure code only executes for mail.. (hopefully?)'
        Set objMailItem = Application.ActiveExplorer.Selection.Item(1) 'if both above conditions are met, sets objMailitem object as the currently selected item'
            objMailItem.Categories = strRemark & "," & objMailItem.Categories 'adds the strRemark string as a new category to objMailitem'
    End If
End If
End Sub

Apologies for the long post, very much appreciate you taking the time to read through some of it!
 
>>
  1. Email was very recently replied to (I replied to it and immediately tried to move it into another folder).
  2. Email cannot be previewed in the viewing pane (Shows the message: "This item cannot be displayed in the reading pane. Open the item to read its contents.").
>>
The first is an IMAP issue - Outlook is bad about registering updates from the server after you make a change to an item. The manual fix is to select another message, come back and move it. I don't have a solution for VBA.

The second usually means there is something in the message that prevents it from displaying - in an Exchange server, it could be embedded objects or custom forms. This is less likely in IMAP. Signed messages will do it too.

If you know what message triggers it, add the message class field to the view and see what message class it is.

Try adding error handling to the sub - before the Set objMailItem line:
either
On Error GoTo 0 or
On Error GoTo ErrorHandler

then at the end
ErrorHandler:
Exit Sub

When you hit an error the message won't move but the
 
Thanks for the feedback Diane!
I'll try adding the error handler, hopefully it'll catch the remaining outliers.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
U Outlook 2019 VBA run-time error 424 Outlook VBA and Custom Forms 2
D We're sorry but outlook has run into an error Using Outlook 6
A Run time error 424. object required in outlook 2013 Outlook VBA and Custom Forms 10
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
P Run Time Error 91 when linking contact to task in VBA Outlook VBA and Custom Forms 1
Vijay Error in rule- Run a script Using Outlook 1
A vb6 run time error 5 when Outlook 2007 Explorer object displayed Outlook VBA and Custom Forms 1
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
V Outlook macros no longer run until VB editor is opened Outlook VBA and Custom Forms 0
J Want to create a button on the nav bar (module add-in) to run code Outlook VBA and Custom Forms 2
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
N Outlook 2021 'Run Script" Rules? Outlook VBA and Custom Forms 4
T Outlook 2010 Errore run-time -2147417851 (80010105) Metodo delete ContactItem non riuscito Outlook VBA and Custom Forms 0
K Run a script rule to auto 'send again' on undeliverable emails? Outlook VBA and Custom Forms 1
G Save attachment run a script rule Outlook VBA and Custom Forms 0
D Outlook 2013 Macros only run in VB editor, not in drop down or button Outlook VBA and Custom Forms 14
M White square in body of Outlook Messages (O2016 Version 2012 32bit Click To Run) Using Outlook 4
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
C Auto Run VBA Code on new email Outlook VBA and Custom Forms 1
Aussie Rules Run a Script on an Incoming Email OK and then the Email reverts Outlook VBA and Custom Forms 0
A Apply Selected Emails to outlook rules and Run Rules Using Outlook 5
B VBScript doesn't run on Recipient Email Outlook VBA and Custom Forms 2
S Outlook Custom Form Scripting only working when clicking on "Run this form" Outlook VBA and Custom Forms 2
Y Outlook 2013 Run A Script Outlook VBA and Custom Forms 4
O Outlook 2016 This rule will only run when you check your email in Outlook.... Using Outlook 4
B run scripts Using Outlook 1
Dave A Run macro on existing appointment when it changes Outlook VBA and Custom Forms 1
O Run macro automatically at sending an email Using Outlook 11
P errors appear every time I run SCANPST Using Outlook 3
B Outlook rule run a Script doesn't work Outlook VBA and Custom Forms 1
B Wanting to run a script that will filter any body that has a russian link in it. Outlook VBA and Custom Forms 5
O Having rules run on old mails noved to inbox Outlook VBA and Custom Forms 8
Bri the Tech Guy Registry Tweak to make "Run a Script" Action Available Outlook VBA and Custom Forms 2
Bri the Tech Guy Run Script rule not running for newly arriving messages Outlook VBA and Custom Forms 25
J Custom form code doesn't run Outlook VBA and Custom Forms 2
J VBA Run When Reply Outlook VBA and Custom Forms 4
Vijay Run script doesn't work in outlook Using Outlook 1
O VBA to Run Font Change on Outlook Startup Outlook VBA and Custom Forms 4
D Creating an outlook session from Access vba but run silently. With A specific profile Outlook VBA and Custom Forms 1
Diane Poremsky Run a Script Rule: Send a New Message when a Message Arrives Using Outlook 2
Diane Poremsky Using Scanpst in Outlook Click to Run Using Outlook 0
oliv- How to Run a Script IN AN ADDIN with Outlook's Rules and Alerts Outlook VBA and Custom Forms 2
L Run a Script Rule doesn't work Using Outlook 5
B Can't run macro from QAT when emailing from Acrobat Outlook VBA and Custom Forms 0
J Outlook 2010 VBScript editor does not run code at all Outlook VBA and Custom Forms 0
X Outlook script to run excel data Outlook VBA and Custom Forms 1
D How to Run a Report Based on Age of Inbox Items Outlook VBA and Custom Forms 0
D RUN SCRIPT WHEN OUTLOOK IS CLOSE Outlook VBA and Custom Forms 1
L Cannot run script from rule Outlook VBA and Custom Forms 7
M Office 365 Click to run BCM (Business Contact Manager) 0

Similar threads

Back
Top