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:
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:
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:
Apologies for the long post, very much appreciate you taking the time to read through some of it!
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:
- Email was very recently replied to (I replied to it and immediately tried to move it into another folder).
- 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.").
- 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:
- The macro is installed on six computers, and I'd say the error occurrence rate is "infrequent".
- The macro seems to work fine for 99% of all email messages.
- All six computers have Microsoft Outlook for Microsoft 365 MSO 32bit installed via Microsoft's installer obtained via portal.office.com.
- 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!