Outlook VBA code stops working intermittently

Adam 6 Reputation points
2021-06-21T08:25:45.803+00:00

Hi - Hoping somebody could help with an ongoing issue with a VBA script used in Outlook:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim xPrompt As String
Dim xOkOrCancel As Integer
On Error Resume Next
xPrompt = "Are you sure you want to send to this person?"
xOkOrCancel = MsgBox(xPrompt, vbOKCancel)
If xOkOrCancel <> vbOK Then
Cancel = True
End If
End Sub

Essentially it just brings a popup when sending an email. The script works great. I have set this up in the Outlook VBA script editor under 'ThisOutlookSession'. Also I have selected the 'Notifications for all macros' setting in Trust center settings. I receive a popup message when opening Outlook to 'Enable Macros' I select enable and all is well.

However, every so often (Maybe once a fortnight) it stops working and I get no popup. No settings have changed in trust center and script is still there in VBA script editor. I normally resolve by removing and re-adding the script > press save > close & reopen Outlook and this seems to sort. It's not a huge problem but can be quite frustrating.

Would anybody know what causes this issue? Or how to stop this happening permanently?

For reference, I'm using Office 365 Outlook desktop app on Windows 10. Any help much appreciated - Thanks

Office Visual Basic for Applications
Office Visual Basic for Applications
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Visual Basic for Applications: An implementation of Visual Basic that is built into Microsoft products.
1,502 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Alan Samuel 1 Reputation point
    2022-08-12T13:43:09.193+00:00

    I have this same issue with code that I have in ThisOutlookSession that analysis each email as it comes in. It happens sometimes once a day or sometimes once a week. I'm also using Outlook 365 desktop app on Windows 10 Pro. I've been using this same code (with minor changes) for 10 years now. It worked fine on Windows 7 Pro using Outlook 2007 and Outlook 2010. I've made sure that the system isn't going to sleep or anything funny like that. Closing Outlook and re-opening get it's working again. How can I capture when ThisOutlookSession stops working?


  2. Oskar Shon 866 Reputation points
    2023-01-04T19:05:14.863+00:00

    Hi I saw that problem many years ago and I decide to move my solutions to vb.net (visual studio)
    Then I use the same procedure like in VBA building add-in and works every each time with Desktop Outlook:

    Private Sub Application_ItemSend(Item As Object, ByRef Cancel As Boolean) Handles Application.ItemSend  
    

    Regards


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.