Trent:
Below is some sample code. You did not say whether you were going to run
this code from Outlook, or another program. The sample below assumes you
are running the code from Outlook. The Body property of the MailItem object
is protected by Outlook security and will generate a security warning for
each MailItem unless you derive the Namespace from Outlook's inherent
Application object. Using the Set ol = New Outlook.Application, will cause
these warnings, for instance.
Function IterateEmails()
Dim olkVBA As Outlook.MAPIFolder
Dim olkNameSpace As Outlook.NameSpace
Dim mi As Outlook.MailItem
On Error GoTo Errorhandler
'Notice that we are using the inherent Outlook Application Object
Set olkNameSpace = Application.GetNamespace("MAPI")
Set olkVBA =
olkNameSpace.GetDefaultFolder(olFolderDrafts).Folders("VBA")
For Each mi In olkVBA.Items
Debug.Print mi.Subject
Debug.Print mi.Body
Next mi
Function_Exit:
Set mi = Nothing
Set olkVBA = Nothing
Set olkNameSpace = Nothing
Exit Function
Errorhandler:
If Err.Number <> 0 Then
MsgBox Err.Description, vbCritical, "Error"
Resume Function_Exit
End If
End Function
--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com
This response is supplied "as is" without any representations or warranties.
David, I followed it upto:
Dim ol As Outlook.Application
Dim olns As Object
Dim MyFolder As Outlook.Folders
Dim myItem As Object
Set ol = New Outlook.Application
Set olns = ol.GetNamespace("MAPI")
Set MyFolder = olns.GetDefaultFolder(olFolderDrafts)
Then got lost. (I added the Dim statements.) I have a folder created off
of the "Drafts" folder called "VBA" for testing purposes. Can you cut to
the
chase of this article and give me the code lines to access email message
text
in this folder?
Thanks,
Trent Argante
[DC.J(125)!(382)]
David Lloyd said:
Trent:
The following KB article may be a good reference:
http://support.microsoft.com/default.aspx?scid=kb;en-us;208520
--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com
This response is supplied "as is" without any representations or
warranties.
I can iterate through an open message's text via the follwoing
declarations:
Dim myOlApp As Object
Dim myItem As Outlook.Inspector
Dim objItem As Object
Dim myBody As Variant
Dim lngMsgLen As Long
Set myOlApp = CreateObject("Outlook.Application")
Set myItem = myOlApp.ActiveInspector
Set objItem = myItem.CurrentItem 'Current eMail MUST BE OPEN!
myBody = objItem.Body
lngMsgLen = Len(myBody)
But, how do I designate a folder, then iterate through all of its
message's
text?
Thanks,
Trent Argante
[DC.J(125)!(382)]