Outlook VBA code stops working intermittently

Adam 6 Reputation points

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

1 vote

2 answers

Sort by: Most helpful
  1. Alan Samuel 1 Reputation point

    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 791 Reputation points MVP

    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