ernst8498
asked on
Save email as text file
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.Appl ication")
Set olNameSpace = olApp.GetNameSpace("MAPI")
Set olFolder = olNameSpace.GetDefaultFold er(6)
Set olRestrictedItems = olFolder.Items.Restrict("[ Subject] = ""Test""")
For Each olItem In olRestrictedItems
'MsgBox olItem.Subject
Set olItem = olApp.ActiveInspector.curr entItem
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
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.Appl
Set olNameSpace = olApp.GetNameSpace("MAPI")
Set olFolder = olNameSpace.GetDefaultFold
Set olRestrictedItems = olFolder.Items.Restrict("[
For Each olItem In olRestrictedItems
'MsgBox olItem.Subject
Set olItem = olApp.ActiveInspector.curr
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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...
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...
Sure, it would go something like this:
Sub RecurseChildFolders(objFol der as Folder, iLevel as Integer)
dim objChild as Folder
debug.print tab(ilevel * 4); objFolder.Name
for each objChild in objFolder.Folders
RecurseChildFolders(objFol der, iLevel + 1)
next
end sub
By the way, I charge extra for simplicity :))
Sub RecurseChildFolders(objFol
dim objChild as Folder
debug.print tab(ilevel * 4); objFolder.Name
for each objChild in objFolder.Folders
RecurseChildFolders(objFol
next
end sub
By the way, I charge extra for simplicity :))
ASKER
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.
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.
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