Manage Inbox with vbscript

Problem . Manage incoming messages using vbscript.

Outlook Version : Outlook 2000

Description I can’t use VBA for this because, as I believe, Outlook 2000 does not allow you to run a VBA script from the rules wizard, and therefore, I must use the Run a Program | VBScript Run a Program | VBScript

What I know : I know how to handle emails from VBA, like this

 Sub Sample(MyMail As MailItem) Dim strID As String, olNS As Outlook.NameSpace Dim olMail As Outlook.MailItem strID = MyMail.EntryID Set olNS = Application.GetNamespace("MAPI") Set olMail = olNS.GetItemFromID(strID) '~~> Rest of the code Set olMail = Nothing Set olNS = Nothing End Sub 

I also know how to run vbscript by email, which is already in the inbox. To run vbscript on OL2000, you must use Run A Program and point it to the vbs file. Run A Script not available in OL2000.

What I do not know : And here I need help. How to get a mail object that didn’t hit the mailbox in VBS. As soon as I receive the object, I can perform the remaining necessary operations.

+4
source share
1 answer

You are right that the OL2000 cannot run the VBA macro from the rule if this article .

This is how I handle incoming emails. It uses VBA, but as far as I know, there is no way in VBScript to do this.

 Private WithEvents Items As Outlook.Items Private Sub Application_Startup() Dim olApp As Outlook.Application Dim objNS As Outlook.NameSpace Set olApp = Outlook.Application Set objNS = olApp.GetNamespace("MAPI") Set Items = objNS.GetDefaultFolder(olFolderInbox).Items End Sub Private Sub Items_ItemAdd(ByVal item As Object) On Error Goto ErrorHandler Dim Msg As Outlook.MailItem If TypeName(item) = "MailItem" Then Set Msg = item '~~> do something with the new message here End If ProgramExit: Exit Sub ErrorHandler: MsgBox Err.Number & " - " & Err.Description Resume ProgramExit End Sub 

This code must be inserted into the ThisOutlookSession module, then Outlook must be restarted.

+2
source

All Articles