?
Solved

Looping through Outlook messages being composed

Posted on 2003-03-05
6
Medium Priority
?
159 Views
Last Modified: 2010-04-07
Using Visual Basic 6 / VBA I would like to know how to loop through some sort of MAPI collection containing messages being composed by the user in Microsoft Outlook (and not saved in the Draft folder).  Anyone done this?
0
Comment
Question by:barnesd1
[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
  • 3
  • 3
6 Comments
 
LVL 10

Accepted Solution

by:
aeklund earned 600 total points
ID: 8073221
You need to loop through the inspectors.. those are the emails being composed...

Here is a sample:

Sub LoopInspectors()
  Dim oOutlook As Outlook.Application
  Set oOutlook = New Outlook.Application
 
  'Dim oNS As NameSpace
  'Set oNS = Outlook.GetNamespace("MAPI")
  'oNS.Logon , , False, False
 
  Dim oInspector As Inspector
  For Each oInspector In oOutlook.Inspectors
    Debug.Print oInspector.Caption
   
    If oInspector.CurrentItem.Class = olMail Then
      Dim oMail As MailItem
      Set oMail = oInspector.CurrentItem
        Debug.Print , oMail.To, oMail.Body
      Set oMail = Nothing
    End If
  Next
 
 
  'oNS.Logoff
  'Set oNS = Nothing
  Set oOutlook = Nothing
End Sub
0
 
LVL 4

Author Comment

by:barnesd1
ID: 8078327
What references are you using please for MAPI?  I referenced msoutl85.olb but it doesn't recognise oOutlook.inspectors as an object!
0
 
LVL 10

Expert Comment

by:aeklund
ID: 8080655
>>Dim oOutlook As Outlook.Application

I'm referencing Microsoft Outlook 9.0 object library
(mso9.dll) (outlook 2000)  it may vary for different versions of outlook
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Author Comment

by:barnesd1
ID: 8088061
This is the solution I used

Dim oOutlook As Outlook.Application
Set oOutlook = New Outlook.Application

'Dim oNS As NameSpace
'Set oNS = oOutlook.GetNamespace("MAPI")
'oNS.Logon , , False, False

DoCmd.OpenReport strReportName, acViewNormal
Call WaitSeconds(5)
res_retry:
oOutlook.ActiveInspector.CurrentItem.Subject = "CapMan Report: " & strReportName & " to " & strBranchName
oOutlook.ActiveInspector.CurrentItem.To = "[Fax:" & SpaceTo_(strBranchName) & "@" & strFaxNumber & "]"
oOutlook.ActiveInspector.CurrentItem.Send
Set oOutlook = Nothing
DoCmd.Close acReport, strReportName, acSaveNo

So aeklund gave me a pointer that it was the activeinspector that I needed to look at but as I'm using Outlook 97 I worked out the properties myself.  Will award 200 points anyway.  Note SpaceTo_ and WaitSeconds are my functions.
0
 
LVL 4

Author Comment

by:barnesd1
ID: 8088068
See my last submission
0
 
LVL 10

Expert Comment

by:aeklund
ID: 8088799
Very good..., I hope you would have let me know that it wasn't 100% what you were looking for so that I could assist further and perhaps of gotten an "A" grade.  You kind of blind sided me there.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

752 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