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

Writing small file for each received Outlook 2003 email message



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old October 3rd 07, 07:26 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 2
Default Writing small file for each received Outlook 2003 email message

totally new to outlook 2003 and VBA, so please be gentle

yesterday, I added this short piece of code via Tools, Macros, Visual
Basic Editor

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Sub CustomMailMessageRule(Item As Outlook.MailItem)

logfile = "C:\Temp\email.txt"

Set fso = CreateObject("Scripting.FileSystemObject")
Set fsOut = fso.OpenTextFile(logfile, ForAppending, True)

outputString = "Mail message arrived: " & Item.Subject
fsOut.WriteLine outputString

fsOut.Close

Set fso = Nothing
Set fsOut = Nothing

End Sub

I then created a rule that for each email on this machine, run script
which I called Sample1

To my surprise, it worked fine and wrote in append mode a line for
each received email.

Today, it does not and I can't figure out why it stopped so I removed
the rule, removed the code and added it back in (closed and opened
OL2003 couple times), but it just won't run any more.

What may I have broken? Other than that OL2003 runs fine

Ads
  #2  
Old October 3rd 07, 07:39 PM posted to microsoft.public.outlook.program_vba
Zoe[_2_]
external usenet poster
 
Posts: 6
Default Writing small file for each received Outlook 2003 email message

a wrote:
totally new to outlook 2003 and VBA, so please be gentle
Today, it does not and I can't figure out why it stopped so I removed
the rule, removed the code and added it back in (closed and opened
OL2003 couple times), but it just won't run any more.

What may I have broken? Other than that OL2003 runs fine


try this:

Close/Exit OL2003
Start OL2003
Press Alt-F11 which brings up the VBA editor
Close the editor

It will now work

Note that it may start prompting you for allowing it to access userid's and
email addresses if you are using
Item.SenderName or Item.SenderEmailAddress and I don't know how to make it
stop asking, especially if you want the machine to automatically keep
writing that information to the file

Perhaps someone else knows how to make it stop asking about "how long to
allow in minutes" access

  #3  
Old October 3rd 07, 08:16 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Writing small file for each received Outlook 2003 email message

Does other VBA code run? If not, check Help | About Microsoft Outlook | Disabled Items.

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


wrote in message ups.com...
totally new to outlook 2003 and VBA, so please be gentle

yesterday, I added this short piece of code via Tools, Macros, Visual
Basic Editor

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Sub CustomMailMessageRule(Item As Outlook.MailItem)

logfile = "C:\Temp\email.txt"

Set fso = CreateObject("Scripting.FileSystemObject")
Set fsOut = fso.OpenTextFile(logfile, ForAppending, True)

outputString = "Mail message arrived: " & Item.Subject
fsOut.WriteLine outputString

fsOut.Close

Set fso = Nothing
Set fsOut = Nothing

End Sub

I then created a rule that for each email on this machine, run script
which I called Sample1

To my surprise, it worked fine and wrote in append mode a line for
each received email.

Today, it does not and I can't figure out why it stopped so I removed
the rule, removed the code and added it back in (closed and opened
OL2003 couple times), but it just won't run any more.

What may I have broken? Other than that OL2003 runs fine

  #4  
Old October 3rd 07, 09:24 PM posted to microsoft.public.outlook.program_vba
[email protected]
external usenet poster
 
Posts: 2
Default Writing small file for each received Outlook 2003 email message

Sue Mosher wrote:
Does other VBA code run? If not, check Help | About Microsoft Outlook | Disabled Items.


there are no disabled items.

As Zoe predicted, it runs fine now but I am being prompted every time
since I wanted to use the Items.SenderName

It's hopeless, can't even have a simple script run in OL2003 due to
security

  #5  
Old October 4th 07, 12:35 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Writing small file for each received Outlook 2003 email message

SenderName shouldn't raise a prompt if the code is constructed properly. In a "run a script" rule procedure, that means getting the item with the Namespace.GetItemFromID method:

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

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
MsgBox msg.SenderName

Set msg = Nothing
Set olNS = Nothing
End Sub

For Outlook VBA basics, see http://outlookcode.com/article.aspx?...tml.htm#ol2002 for another example.


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


wrote in message s.com...
Sue Mosher wrote:
Does other VBA code run? If not, check Help | About Microsoft Outlook | Disabled Items.


there are no disabled items.

As Zoe predicted, it runs fine now but I am being prompted every time
since I wanted to use the Items.SenderName

It's hopeless, can't even have a simple script run in OL2003 due to
security

 




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
.ics file attachment being received as plain text message by outlook [email protected] Outlook - Calandaring 1 September 25th 07 03:24 AM
Outlook 2003 - contact list not showing up when writing new email Carol M Outlook - Using Contacts 1 July 14th 07 03:14 AM
I cannot open a URL in a received email message in Outlook 2003 Paul Mayer Outlook - General Queries 1 July 11th 07 08:00 PM
I received the message"this file can Minneapois Outlook - Calandaring 0 October 30th 06 06:06 PM
writing email get word error message interface not supported Erik R Outlook - General Queries 2 October 12th 06 07:28 PM


All times are GMT +1. The time now is 08:14 AM.


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.