![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
I am using Outlook 2003.
I want to access a group of emails that are in an Outlook folder. I will be parsing the contents of the email and either writing them out to a csv file, or into an Access database. Can someone either (1) give me an idea how to do this, or (2) point me to a site where I can get some help? TIA, Larry Woods |
Ads |
#2
|
|||
|
|||
![]()
Hi,
Copy and paste the following function directly into MS Outlook VB Module. Function ReadItemsInFolder() Dim olNms As NameSpace Dim olFdr As MAPIFolder Dim olMItem As MailItem Dim obj As Object Dim strBody As String Set olNms = GetNamespace("MAPI") Set olFdr = olNms.PickFolder For Each obj In olFdr.Items 'Folders can contain many different item types so you need to assign each item to 'a generic object then check the class for the item(s) you want If obj.Class = olMail Then 'Picks only the mail items Set olMItem = obj strBody = olMItem.Body 'strBody now contains the message body text. Parse this variable into your other source (csv, access etc) End If Next Set olMItem = Nothing Set obj = Nothing Set olFdr = Nothing Set olNms = Nothing End Function If the VB module is in MS Access, you should: - Add the Outlook Libarary as a reference - Precede each Outlook object with Outlook. in the declaration section and - Create an Application object For instance, replace the appropriate lines in the above function with the following: Dim olApp as New Outlook.Application 'New line Dim olNms As Outlook.NameSpace Dim olFdr As Outlook.MAPIFolder Dim olMItem as Outlook.MailItem Set olNms = olApp.GetNamespace("MAPI") Good luck! Greg J lwoods wrote: I am using Outlook 2003. I want to access a group of emails that are in an Outlook folder. I will be parsing the contents of the email and either writing them out to a csv file, or into an Access database. Can someone either (1) give me an idea how to do this, or (2) point me to a site where I can get some help? TIA, Larry Woods |
#3
|
|||
|
|||
![]()
Thanks, Greg....
I wanted to acknowledge your reply...and I will try out the code ASAP, but I have a disk crash right now! (Doesn't it ALWAYS happen when you get behind?) I'll get back to you. Larry Woods "Greg J" wrote in message oups.com... Hi, Copy and paste the following function directly into MS Outlook VB Module. Function ReadItemsInFolder() Dim olNms As NameSpace Dim olFdr As MAPIFolder Dim olMItem As MailItem Dim obj As Object Dim strBody As String Set olNms = GetNamespace("MAPI") Set olFdr = olNms.PickFolder For Each obj In olFdr.Items 'Folders can contain many different item types so you need to assign each item to 'a generic object then check the class for the item(s) you want If obj.Class = olMail Then 'Picks only the mail items Set olMItem = obj strBody = olMItem.Body 'strBody now contains the message body text. Parse this variable into your other source (csv, access etc) End If Next Set olMItem = Nothing Set obj = Nothing Set olFdr = Nothing Set olNms = Nothing End Function If the VB module is in MS Access, you should: - Add the Outlook Libarary as a reference - Precede each Outlook object with Outlook. in the declaration section and - Create an Application object For instance, replace the appropriate lines in the above function with the following: Dim olApp as New Outlook.Application 'New line Dim olNms As Outlook.NameSpace Dim olFdr As Outlook.MAPIFolder Dim olMItem as Outlook.MailItem Set olNms = olApp.GetNamespace("MAPI") Good luck! Greg J lwoods wrote: I am using Outlook 2003. I want to access a group of emails that are in an Outlook folder. I will be parsing the contents of the email and either writing them out to a csv file, or into an Access database. Can someone either (1) give me an idea how to do this, or (2) point me to a site where I can get some help? TIA, Larry Woods |
#4
|
|||
|
|||
![]()
Greg,
It works in debug mode, but when I try to open any of the menu items in the VB IDE, they are disabled; also all toolbar icons. What am I doing wrong. I need to add fso in order to write out a csv file. TIA, Larry "Greg J" wrote in message oups.com... Hi, Copy and paste the following function directly into MS Outlook VB Module. Function ReadItemsInFolder() Dim olNms As NameSpace Dim olFdr As MAPIFolder Dim olMItem As MailItem Dim obj As Object Dim strBody As String Set olNms = GetNamespace("MAPI") Set olFdr = olNms.PickFolder For Each obj In olFdr.Items 'Folders can contain many different item types so you need to assign each item to 'a generic object then check the class for the item(s) you want If obj.Class = olMail Then 'Picks only the mail items Set olMItem = obj strBody = olMItem.Body 'strBody now contains the message body text. Parse this variable into your other source (csv, access etc) End If Next Set olMItem = Nothing Set obj = Nothing Set olFdr = Nothing Set olNms = Nothing End Function If the VB module is in MS Access, you should: - Add the Outlook Libarary as a reference - Precede each Outlook object with Outlook. in the declaration section and - Create an Application object For instance, replace the appropriate lines in the above function with the following: Dim olApp as New Outlook.Application 'New line Dim olNms As Outlook.NameSpace Dim olFdr As Outlook.MAPIFolder Dim olMItem as Outlook.MailItem Set olNms = olApp.GetNamespace("MAPI") Good luck! Greg J lwoods wrote: I am using Outlook 2003. I want to access a group of emails that are in an Outlook folder. I will be parsing the contents of the email and either writing them out to a csv file, or into an Access database. Can someone either (1) give me an idea how to do this, or (2) point me to a site where I can get some help? TIA, Larry Woods |
#5
|
|||
|
|||
![]()
Hmmm, not sure about why your menu items and toolbars would be
disabled. Try changing the function to a Sub, that way it will appear in the list when you click Tools Macros and you can run the code from Outlook interface instead of the code module. As far as FSO goes, link the reference called Windows Script Host Object Model, or a much simpler way is to use the following code with existing references. To get extra help with this, position the cursor on 'Open' and press F1, it should open a page describing the 'Open Statement'. Open "e:\test.csv" For Output As #1 'Opens a file ready for input Print #1, "test1" 'Writes a new line to the file Print #1, "test2" 'Writes a new line to the file Print #1, "test3" 'Writes a new line to the file Close #1 'Closes the file So to get this code to work you would create a variable that contains the entire contents of a line then use the Print statement to write the whole line to the file. The file called e:\test.csv contains the following: test1 test2 test3 Hope this helps Greg J |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Where are Local Folder E-mails Stored? | illinifan1985 | Outlook Express | 4 | July 9th 06 05:34 PM |
Selective Read Receipts VBA using run a script rule | prideoflions | Outlook and VBA | 5 | May 26th 06 03:31 PM |
VBA to move outbound email and mark as read? | [email protected] | Outlook and VBA | 11 | May 2nd 06 03:07 PM |
OE6 'stored folder' problem | Aya | Outlook Express | 3 | April 26th 06 01:52 AM |
How do I call a stored procedure inside my sql with a vba script? | Computer Newbie | Outlook and VBA | 1 | March 14th 06 07:08 AM |