Hi,
I leave outlook open 24/7 on a machine so that it can process emails received during the night (It receives data files during this time which are then processed ready for use at a more sociable time).
I used to use rules to run a script in Outlook 2007. However in later versions these options were hidden by default and banned by our IT because the option to enable them was termed "Enable unsafe rules".
As a result I started using an event listener (code below). This worked well until fairly recently where it now seems that the macros disable themselves after a period of in activity which requires a re-start to correct.
To counter this I have had to create a scheduled task to close and re-open outlook periodically during the night. This solves the problem but isn't ideal and doesn't address or explain the underlying cause.
Has anyone else experienced this or have any suggestions?
Code:
'In ThisOutlookSession
Private WithEvents inboxItems As Outlook.Items 'event listener for incoming messages
Public Sub Application_Startup()
'initialise application objects
Dim outlookApp As Outlook.Application
Dim objectNS As Outlook.NameSpace
Set outlookApp = Outlook.Application
Set objectNS = outlookApp.GetNamespace("MAPI")
Set inboxItems = objectNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub inboxItems_ItemAdd(ByVal Item As Object)
'process items received to the inbox
Dim msg As Outlook.MailItem
If TypeName(Item) = "MailItem" then
'routine called to check the mail details and process attachments
end if
end sub
Bookmarks