A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

How do I call a VBA macro to process every incoming message?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 28th 08, 11:07 AM posted to microsoft.public.outlook.program_vba
Rob
external usenet poster
 
Posts: 146
Default How do I call a VBA macro to process every incoming message?

I need to call a COM component to process each incoming message. I can write
VBA to call it and get the response, but I can't find out how to invoke a VBA
function from an Outlook rule.


  #2  
Old February 28th 08, 01:51 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default How do I call a VBA macro to process every incoming message?

A VBA procedure to be called by a "run a script" rule action needs a MailItem or MeetingItem as its parameter. That item is processed by the code:

Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim msg As Outlook.MailItem
Dim rply as Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
Set rply = msg.Reply
rply.Body = "What you want the reply to say."
rply.To = ; "
rply.Send

Set msg = Nothing
Set rply = Nothing
Set olNS = Nothing
End Sub

For more examples of "run a script" rule actions, see:

http://www.outlookcode.com/d/code/zaphtml.htm#ol2002
http://www.outlookcode.com/codedetail.aspx?id=1494


--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"rob" wrote in message ...
I need to call a COM component to process each incoming message. I can write
VBA to call it and get the response, but I can't find out how to invoke a VBA
function from an Outlook rule.


  #3  
Old February 28th 08, 03:01 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default How do I call a VBA macro to process every incoming message?

Public Sub Foobar(item As MailItem)
' blah, blah
End Sub

Have your rule call Foobar from the "run a script" action in the rules
wizard.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"rob" wrote in message
...
I need to call a COM component to process each incoming message. I can
write
VBA to call it and get the response, but I can't find out how to invoke a
VBA
function from an Outlook rule.



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
++++ Can I use macro to monitor incoming messages ? Ian Outlook and VBA 5 May 8th 07 03:54 AM
Call macro from userdefined Ribbon Steffen Grellmann Add-ins for Outlook 5 March 22nd 07 01:18 PM
OH YES I THINK THEY DID CALL MR BUT I DID NOT TALK TO THEM MY MAMA SAI CALL HER BACK LATER CUZ SHE IS DOING SOMETHG RIGHT NOW WHY DID YOU CALL ME NO THEIR IS ONLY ONE ME YES SIR Outlook Express 0 February 25th 07 08:12 AM
Call macro stored in Excel workbook from Outlook's macro Gvaram Outlook and VBA 5 October 4th 06 06:26 AM
Macro to open, retrieve contents, print, and loop through process Michelle Marie Outlook and VBA 2 February 24th 06 09:39 AM


All times are GMT +1. The time now is 12:22 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.