Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Save email as text file

Posted on 2001-06-15
5
Medium Priority
?
183 Views
Last Modified: 2010-05-02
Using the enclosed code to restrict emails and then save each one as a text file to a directory.  However, it chokes using the activeInspector statement and chokes without it.  I am using Access 97 wiht the Outlook 98 reference library.  What am I missing here.  Addtionally, I will want to delete each message when I am done with it.

The error I get is

Object varibale or With Block variable not set..


Thx...


Public Sub getEmail()

' Dimension varibles
Dim olApp As Outlook.Application
Dim olNameSpace As Outlook.NameSpace
Dim olFolder As MAPIFolder
Dim olRestrictedItems As Outlook.Items
Dim olItem As MailItem
Dim olSaveItem As MailItem

    Set olApp = CreateObject("Outlook.Application")
    Set olNameSpace = olApp.GetNameSpace("MAPI")
    Set olFolder = olNameSpace.GetDefaultFolder(6)
       
       
    Set olRestrictedItems = olFolder.Items.Restrict("[Subject] = ""Test""")
   
    For Each olItem In olRestrictedItems
        'MsgBox olItem.Subject
       
        Set olItem = olApp.ActiveInspector.currentItem
        olItem.SaveAs "C:\My Documents\" & olItem.Subject & Date & Time() & ".txt", olTXT
 

    Next
   
Set olApp = Nothing
Set olNameSpace = Nothing
Set olFolder = Nothing
Set olRestrictedItems = Nothing
Set olItem = Nothing


End Sub
0
Comment
Question by:ernst8498
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 800 total points
ID: 6195478
You should be able to lose the SetolItem=olApp.Activeinspector line as it doesn't do anything for you.

The problem perhaps is in the date and time suffix to the filename, try using

olItem.SaveAs "c:\My documents\" & olItem.Subject & Format(Now,"yyyy-mm-dd hh_mm_ss") & ".txt",olTxt

In order to avoid having "\" and "." characters in the filename. This may still cause problems if you have characters in the Subject that cannot form part of a filename.
0
 
LVL 5

Expert Comment

by:gbaren
ID: 6195615
ernst,

You are including a date in the file name you are saving. That date has illegal characters for a file name. You can't use a forward slash in a file name.

Gary
0
 

Author Comment

by:ernst8498
ID: 6196094
This worked - my mistake.  DAAA

Anyway - perhaps you could extend me something else for the 200 pts.  I am looking for a way to recursively loop through all the folders in outlook.  Do you have a code snippet that does this neatly??  Or can you put in the right direction.

Thx.  I will give you the points anyway...
0
 
LVL 5

Expert Comment

by:gbaren
ID: 6196265
Sure, it would go something like this:

Sub RecurseChildFolders(objFolder as Folder, iLevel as Integer)
dim objChild as Folder

    debug.print tab(ilevel * 4); objFolder.Name
    for each objChild in objFolder.Folders
        RecurseChildFolders(objFolder, iLevel + 1)
    next
end sub


By the way, I charge extra for simplicity :))
0
 

Author Comment

by:ernst8498
ID: 6207338
Tim,

This did fix my problem.  

I will repost the question for the recursive folder loop and give those points to the person that offered up the simple script for that.  

Thanks to all.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question