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

Problems with Processing Emails



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 27th 08, 08:00 AM posted to microsoft.public.outlook.program_vba
Trefor
external usenet poster
 
Posts: 27
Default Problems with Processing Emails

Office 2003
Excel Macro Security = Medium

I have created a rule in Outlook to move all emails from a certain person
and/or subject from the Inbox to a folder. This is a shared Mailbox, so many
people may access to the mailbox, but the rule will apply for all. Then I
thought I would “process” the emails with some VBA.

Essentially I want to see if the email contains certain text in the body, if
the result is positive I will Parse the text, pull out the data I want, write
it to a text file, mark the email read and move it to a “processed” folder.
If the test is negative I will simply delete the email.

I am planning to manually run this code from Excel, but would this be better
run from Outlook?

I am getting Security Dialogs, how do I avoid this?

The below started from some code on Dicks-Clicks, but has been filled out
with research from both the Excel and Outlook Discussion Groups.


Sub GetBodyFromInbox()
' http://www.dicks-clicks.com/excel/olRetrieving.htm

Dim olApp As Outlook.Application
Dim olNS As Namespace
Dim InputFolder As Outlook.MAPIFolder
Dim ProcessedFolder As Outlook.MAPIFolder

Dim olMail As Outlook.MailItem
Dim olMail2 As Outlook.MailItem
Dim OutlookMailID As String
Dim MessageText As String

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set InputFolder = olNS.Folders("Mailbox - Test").Folders("Order
Notification")
Set ProcessedFolder = olNS.Folders("Mailbox - Test").Folders("Order
Notification Processed")

For Each olMail In InputFolder.Items
OutlookMailID = olMail.EntryID
Set olMail2 = olNS.GetItemFromID(OutlookMailID)

MessageText = olMail2.Body

If InStr(MessageText, "my text") 0 Then
' Parse this email.

olMail2.UnRead = False
olMail2.Move ProcessedFolder
olMail2.UnRead = False ' Per suggestion from Ken Slovak re maybe
having to set this twice.
Else
' Mail is NOT Order Notification and should be deleted
olMail2.Delete
End If
Next olMail

Set InputFolder = Nothing
Set ProcessedFolder = Nothing
Set olNS = Nothing
Set olApp = Nothing
Set olMail2 = Nothing
End Sub


--
Trefor
Ads
  #2  
Old May 27th 08, 08:36 AM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Problems with Processing Emails


If you run the code in Outlook 2003 or 2007 and don't create a new
Application object but use the instrinsic one, you wouldn't get the security
prompt.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool:
: http://www.vboffice.net/product.html?pub=6&lang=en

Am Tue, 27 May 2008 00:00:00 -0700 schrieb Trefor:

Office 2003
Excel Macro Security = Medium

I have created a rule in Outlook to move all emails from a certain person
and/or subject from the Inbox to a folder. This is a shared Mailbox, so

many
people may access to the mailbox, but the rule will apply for all. Then I
thought I would “process” the emails with some VBA.

Essentially I want to see if the email contains certain text in the body,

if
the result is positive I will Parse the text, pull out the data I want,

write
it to a text file, mark the email read and move it to a “processed”

folder.
If the test is negative I will simply delete the email.

I am planning to manually run this code from Excel, but would this be

better
run from Outlook?

I am getting Security Dialogs, how do I avoid this?

The below started from some code on Dicks-Clicks, but has been filled out
with research from both the Excel and Outlook Discussion Groups.


Sub GetBodyFromInbox()
' http://www.dicks-clicks.com/excel/olRetrieving.htm

Dim olApp As Outlook.Application
Dim olNS As Namespace
Dim InputFolder As Outlook.MAPIFolder
Dim ProcessedFolder As Outlook.MAPIFolder

Dim olMail As Outlook.MailItem
Dim olMail2 As Outlook.MailItem
Dim OutlookMailID As String
Dim MessageText As String

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set InputFolder = olNS.Folders("Mailbox - Test").Folders("Order
Notification")
Set ProcessedFolder = olNS.Folders("Mailbox - Test").Folders("Order
Notification Processed")

For Each olMail In InputFolder.Items
OutlookMailID = olMail.EntryID
Set olMail2 = olNS.GetItemFromID(OutlookMailID)

MessageText = olMail2.Body

If InStr(MessageText, "my text") 0 Then
' Parse this email.

olMail2.UnRead = False
olMail2.Move ProcessedFolder
olMail2.UnRead = False ' Per suggestion from Ken Slovak re

maybe
having to set this twice.
Else
' Mail is NOT Order Notification and should be deleted
olMail2.Delete
End If
Next olMail

Set InputFolder = Nothing
Set ProcessedFolder = Nothing
Set olNS = Nothing
Set olApp = Nothing
Set olMail2 = Nothing
End Sub

  #3  
Old May 27th 08, 11:45 AM posted to microsoft.public.outlook.program_vba
Trefor
external usenet poster
 
Posts: 27
Default Problems with Processing Emails

Michael,

Many thanks for you reply.

Sorry but I am new to this, what does this "don't create a new Application
object but use the instrinsic one" mean? In my example code, have I done
something that breaks this rule? If so are you able to assist with what is
wrong?


--
Trefor


"Michael Bauer [MVP - Outlook]" wrote:


If you run the code in Outlook 2003 or 2007 and don't create a new
Application object but use the instrinsic one, you wouldn't get the security
prompt.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool:
: http://www.vboffice.net/product.html?pub=6&lang=en

Am Tue, 27 May 2008 00:00:00 -0700 schrieb Trefor:

Office 2003
Excel Macro Security = Medium

I have created a rule in Outlook to move all emails from a certain person
and/or subject from the Inbox to a folder. This is a shared Mailbox, so

many
people may access to the mailbox, but the rule will apply for all. Then I
thought I would “process” the emails with some VBA.

Essentially I want to see if the email contains certain text in the body,

if
the result is positive I will Parse the text, pull out the data I want,

write
it to a text file, mark the email read and move it to a “processed”

folder.
If the test is negative I will simply delete the email.

I am planning to manually run this code from Excel, but would this be

better
run from Outlook?

I am getting Security Dialogs, how do I avoid this?

The below started from some code on Dicks-Clicks, but has been filled out
with research from both the Excel and Outlook Discussion Groups.


Sub GetBodyFromInbox()
' http://www.dicks-clicks.com/excel/olRetrieving.htm

Dim olApp As Outlook.Application
Dim olNS As Namespace
Dim InputFolder As Outlook.MAPIFolder
Dim ProcessedFolder As Outlook.MAPIFolder

Dim olMail As Outlook.MailItem
Dim olMail2 As Outlook.MailItem
Dim OutlookMailID As String
Dim MessageText As String

Set olApp = New Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set InputFolder = olNS.Folders("Mailbox - Test").Folders("Order
Notification")
Set ProcessedFolder = olNS.Folders("Mailbox - Test").Folders("Order
Notification Processed")

For Each olMail In InputFolder.Items
OutlookMailID = olMail.EntryID
Set olMail2 = olNS.GetItemFromID(OutlookMailID)

MessageText = olMail2.Body

If InStr(MessageText, "my text") 0 Then
' Parse this email.

olMail2.UnRead = False
olMail2.Move ProcessedFolder
olMail2.UnRead = False ' Per suggestion from Ken Slovak re

maybe
having to set this twice.
Else
' Mail is NOT Order Notification and should be deleted
olMail2.Delete
End If
Next olMail

Set InputFolder = Nothing
Set ProcessedFolder = Nothing
Set olNS = Nothing
Set olApp = Nothing
Set olMail2 = Nothing
End Sub


  #4  
Old May 27th 08, 08:40 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default Problems with Processing Emails



Remove this line:
Set olApp = New Outlook.Application

Then replace all remaining 'olApp' by 'Application'.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool:
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Tue, 27 May 2008 03:45:00 -0700 schrieb Trefor:

Michael,

Many thanks for you reply.

Sorry but I am new to this, what does this "don't create a new Application
object but use the instrinsic one" mean? In my example code, have I done
something that breaks this rule? If so are you able to assist with what is
wrong?

  #5  
Old May 28th 08, 10:21 AM posted to microsoft.public.outlook.program_vba
Trefor
external usenet poster
 
Posts: 27
Default Problems with Processing Emails

Michael,

I had to make a few other changes, but you certainly pointed me in the right
direction. Many thanks.

--
Trefor


"Michael Bauer [MVP - Outlook]" wrote:



Remove this line:
Set olApp = New Outlook.Application

Then replace all remaining 'olApp' by 'Application'.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool:
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Tue, 27 May 2008 03:45:00 -0700 schrieb Trefor:

Michael,

Many thanks for you reply.

Sorry but I am new to this, what does this "don't create a new Application
object but use the instrinsic one" mean? In my example code, have I done
something that breaks this rule? If so are you able to assist with what is
wrong?


  #6  
Old June 4th 08, 11:16 AM posted to microsoft.public.outlook.program_vba
Ramon
external usenet poster
 
Posts: 1
Default Problems with Processing Emails

Trefor,

Which changes, please ?

Best regards,

Ramon

"Trefor" wrote:

Michael,

I had to make a few other changes, but you certainly pointed me in the right
direction. Many thanks.

--
Trefor


"Michael Bauer [MVP - Outlook]" wrote:



Remove this line:
Set olApp = New Outlook.Application

Then replace all remaining 'olApp' by 'Application'.

--
Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool:
: http://www.vboffice.net/product.html?pub=6&lang=en


Am Tue, 27 May 2008 03:45:00 -0700 schrieb Trefor:

Michael,

Many thanks for you reply.

Sorry but I am new to this, what does this "don't create a new Application
object but use the instrinsic one" mean? In my example code, have I done
something that breaks this rule? If so are you able to assist with what is
wrong?


 




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
Processing incoming emails John[_11_] Outlook and VBA 3 May 21st 08 05:42 PM
Processing incoming emails John[_11_] Add-ins for Outlook 3 May 21st 08 05:42 PM
Processing incoming emails John[_11_] Outlook and VBA 0 May 20th 08 09:06 PM
Processing incoming emails John[_11_] Add-ins for Outlook 0 May 20th 08 09:06 PM
Problems with emails medic676 Outlook - Installation 2 August 20th 07 03:58 PM


All times are GMT +1. The time now is 05:20 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.