Search code examples
vbaoutlookwindows-10windows-update

VBA code in Outlook 2016 and 2019 works different


I have two PC setups:

  1. Win10 Pro Build 1909 with Outlook 2019 for Business
  2. Win10 Pro Build 2004 with Outlook 2016 for Business

(everything original)

My question is, why same VBA code work in 2019 and didnt work in Outlook 2016. Problem is with Outlook or different version of build MS Win10 ?

This part of code didnt work:

ThisOutlookSession

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)

     Dim objMailPuvodni As Outlook.MailItem
     Dim CurrentItem As Object
     Dim lngOdpoved As Long


     Select Case TypeName(Application.ActiveWindow)
     Case "Inspector"
        
        Set objMailPuvodni = Application.ActiveInspector.CurrentItem
    Case "Explorer"
        
        If Application.ActiveExplorer.Selection.Item(1).Class = _
           OlObjectClass.olMail Then
            
            Set objMailPuvodni = _
            Application.ActiveExplorer.Selection.Item(1)
        End If
    End Select


    lngOdpoved = MsgBox("text", _
                    vbQuestion + vbYesNoCancel + vbDefaultButton2, _
                    "Send")

    Select Case lngOdpoved
        Case vbCancel
            Cancel = True
        Case vbNo
        
        Cancel = False
            Case vbYes
        
        Call SifrovatZip(objMailPuvodni)
        
        Cancel = True
    End Select


    Set objMailPuvodni = Nothing

End Sub

UPDATE @nilton answer works


Solution

  • @nilton's answer in the comments works:

    Typically this is due to forgetting to allow macros Enable or disable macros in Office files when upgrading.