La regla "Ejecutar script" de Outlook no activa el script VBA para los mensajes entrantes
Estoy creando este nuevo tema por consejo de otro miembro. Para obtener más información sobre cómo llegaron las cosas en este punto, veaesta pregunta.
Tengo este script VBA, que sé que funcionaSi Se activa. Si uso la subrutina TestLaunch con un mensaje que ya está en mi bandeja de entrada que cumple con los criterios de la regla (pero, por supuesto, no está siendo expulsado por la regla), activará el enlace que quiero que se active sin problemas. Si, cuando creo la regla, digo que la aplique a todos los mensajes existentes en mi bandeja de entrada, funciona perfectamente. Sin embargo, donde se necesita,cuando llegan nuevos mensajes no es asi.
Sé que el script no se activa porque si tengo una regla como esta:
Regla "Nuevo mensaje" de Outlook que tiene habilitado "reproducir sonido"
con "Reproducir un sonido" como parte de él, el sonido siempre se reproduce cuando llega un mensaje de cualquiera de los dos remitentes especificados, por lo que se activa la regla. He eliminado el sonido que juega la parte de la regla, y lo he integrado en el código VBA para fines de prueba en su lugar:
Option Explicit
Private Declare Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal Operation As String, _
ByVal Filename As String, _
Optional ByVal Parameters As String, _
Optional ByVal Directory As String, _
Optional ByVal WindowStyle As Long = vbMinimizedFocus _
) As Long
Private Declare Function sndPlaySound32 _
Lib "winmm.dll" _
Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long
Sub PlayTheSound(ByVal WhatSound As String)
If Dir(WhatSound, vbNormal) = "" Then
' WhatSound is not a file. Get the file named by
' WhatSound from the Windows\Media directory.
WhatSound = Environ("SystemRoot") & "\Media\" & WhatSound
If InStr(1, WhatSound, ".") = 0 Then
' if WhatSound does not have a .wav extension,
' add one.
WhatSound = WhatSound & ".wav"
End If
If Dir(WhatSound, vbNormal) = vbNullString Then
Beep ' Can't find the file. Do a simple Beep.
Exit Sub
End If
Else
' WhatSound is a file. Use it.
End If
sndPlaySound32 WhatSound, 0& ' Finally, play the sound.
End Sub
Public Sub OpenLinksMessage(olMail As Outlook.MailItem)
Dim Reg1 As RegExp
Dim AllMatches As MatchCollection
Dim M As Match
Dim strURL As String
Dim RetCode As Long
Set Reg1 = New RegExp
With Reg1
.Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$;_])*)"
.Global = True
.IgnoreCase = True
End With
PlayTheSound "chimes.wav"
' If the regular expression test for URLs in the message body finds one or more
If Reg1.test(olMail.Body) Then
' Use the RegEx to return all instances that match it to the AllMatches group
Set AllMatches = Reg1.Execute(olMail.Body)
For Each M In AllMatches
strURL = M.SubMatches(0)
' Don't activate any URLs that are for unsubscribing; skip them
If InStr(1, strURL, "unsubscribe") Then GoTo NextURL
' If the URL ends with a > from being enclosed in darts, strip that > off
If Right(strURL, 1) = ">" Then strURL = Left(strURL, Len(strURL) - 1)
' The URL to activate to accept must contain both of the substrings in the IF statement
If InStr(1, strURL, ".com") Then
PlayTheSound "TrainWhistle.wav"
' Activate that link to accept the job
RetCode = ShellExecute(0, "Open", "http://nytimes.com")
Set Reg1 = Nothing
Exit Sub
End If
NextURL:
Next
End If
Set Reg1 = Nothing
End Sub
Private Sub TestLaunchURL()
Dim currItem As MailItem
Set currItem = ActiveExplorer.Selection(1)
OpenLinksMessage currItem
End Sub
que debería reproducir "chimes.wav" si el script VBA se activa en todos los casos y reproducir "TrainWhistle.wav" si se produce el proceso de activación de mi enlace real. Cuando llegan nuevos mensajes, tampoco sucede nada, pero si hay un "Reproducir sonido" en la regla de Outlook que debería ejecutar este script, ese sonido se reproduce.
En este momento tengo la configuración del Centro de confianza para que las macros permitan todo, ya que Outlook estaba de mal humor al firmar que usaba selfcert.exe anteriormente en el proceso de prueba. Realmente me gustaría poder elevar las macroprotecciones nuevamente en lugar de dejarlas en "ejecutar todo" cuando todo esto esté hecho.
Pero, en primer lugar, no puedo entender por mi vida por qué este script se ejecutará perfectamente a través del depurador o si se aplica a los mensajes existentes, pero no se activa por la misma regla de Outlook aplicada a los mensajes existentes cuando un mensaje nuevo real llega Esto es cierto en Outlook 2010, donde estoy desarrollando este script, y también en Outlook 2016, en la máquina de un amigo donde se está implementando.
Cualquier orientación para resolver este problema sería muy apreciada.