PC Review


Reply
Thread Tools Rate Thread

Catch specific emails and respond

 
 
New Member
Molly Coddlez's Avatar
Join Date: Mar 2011
Location: Manchester
Posts: 19
 
      15th Mar 2011
Hi peeps, im kinda new to VBA, but i'm quite grounded in VB6 and i need to make a macro for my outlook 2k7

The idea is i want to trigger the event for every new unread email, check the subject and the address its sent from, and when that corresponds i need to pull info out of it, store it in an MDB (which i have a little experience with) and then create a response, but not responding to the sender instead responding to an email address i harvest from the email itself.

The problem is i dont know the events and syntax of outlook VBA hardly at all.

can anyone give me a few pointers please, even some links to nice noob tutorials would help.

Thanks in advance

Molly
 
Reply With Quote
 
 
 
 
New Member
JensCarlberg's Avatar
Join Date: Mar 2011
Location: Linköping, Sweden
Posts: 6
 
      16th Mar 2011
Hi!

I have recently been doing something pretty much along these lines; I'm posting what I have that I believe is relevant for you. All the code is in the ThisOutlookSession in the VBA editor.

-------- 8< --------
Public WithEvents objInbox As Outlook.Items

Private Sub Application_Startup()
Set objInbox = Session.GetDefaultFolder(olFolderInbox).Items
End Sub

Sub DoStuff(ByRef Item As Outlook.MailItem)
MsgBox "Subject: " & Item.Subject & ", sender: " & Item.SenderEmailAddress
End Sub

Private Sub objInbox_ItemAdd(ByVal Item As Object)
If Item.Class = olMail Then
DoStuff Item
End If
End Sub
-------- 8< --------

Two links regarding what I do above:

http://msdn.microsoft.com/en-us/libr...ffice.11).aspx
http://msdn.microsoft.com/en-us/libr...ffice.11).aspx

Hopefully this will get you started!

///BR, Jens Carlberg
 
Reply With Quote
 
New Member
Molly Coddlez's Avatar
Join Date: Mar 2011
Location: Manchester
Posts: 19
 
      16th Mar 2011
thanks. i tried it but it doesnt seem to be firing when i get a new mail. i tested it by inserting msgboxes at each point, but DoStuff never triggers.

what am i doing wrong? am i missing a reference library?
 
Reply With Quote
 
New Member
JensCarlberg's Avatar
Join Date: Mar 2011
Location: Linköping, Sweden
Posts: 6
 
      16th Mar 2011
I'm using Outlook 2003. If you are using another version, I image there might be differences.

Also, I often have to restart Outlook to get my macros to work; when starting Outlook, I get a question if I want to enable macros.

Other than that, I'm out of ideas.

///BR, Jens C
 
Reply With Quote
 
New Member
Molly Coddlez's Avatar
Join Date: Mar 2011
Location: Manchester
Posts: 19
 
      16th Mar 2011
pants. im using outlook 2k7, and i think ive got it sorted now.

Code:
Option Explicit

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
  Dim objItem As MailItem
  Set objItem = Application.Session.GetItemFromID(EntryIDCollection)

  If fTestIncoming(objItem) = True Then sProcessIncoming objItem
End Sub

Function fTestIncoming(objNewMail As MailItem) As Boolean
  Dim blnIsRelevant As Boolean
  blnIsRelevant = False
  If LCase(objNewMail.SenderEmailAddress) = "(E-Mail Removed)" And LCase(objNewMail.Subject) = "enlarge your pens" Then
    blnIsRelevant = True
  End If
  fTestIncoming = blnIsRelevant

End Function

Sub sProcessIncoming(objNewMail As MailItem)
'stuff happens
End Sub
now all i need is to get the STUFF to HAPPEN

any idea how i connect an mdb to outlook? i need to push/pull tables in an external mdb now and i have NO idea how i assign an external database to the Database variable
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find Specific Exception to Catch. joseph@copticmail.com Microsoft C# .NET 3 30th Nov 2006 12:56 PM
Can Outlook Auto respond with a specific Y/N response to emails r. =?Utf-8?B?c3RpbGxfY3JhenlfYWZ0ZXJfYWxsLi4u?= Microsoft Outlook Discussion 1 1st May 2006 07:14 PM
Respond at a specific time =?Utf-8?B?Q2F0X01hbg==?= Microsoft Excel Programming 1 14th Jan 2006 07:54 PM
Try Catch Question How Make it go to specific catch? needin4mation@gmail.com Microsoft C# .NET 3 10th Oct 2005 08:59 PM
Outlook doesn't respond on specific emails Gary Adamson Microsoft Outlook Discussion 1 28th Oct 2003 04:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:02 PM.