Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 162
  • Last Modified:

Looping through Outlook messages being composed

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
barnesd1
Asked:
barnesd1
  • 3
  • 3
1 Solution
 
aeklundCommented:
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
 
barnesd1Author Commented:
What references are you using please for MAPI?  I referenced msoutl85.olb but it doesn't recognise oOutlook.inspectors as an object!
0
 
aeklundCommented:
>>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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
barnesd1Author Commented:
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
 
barnesd1Author Commented:
See my last submission
0
 
aeklundCommented:
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now