Link to home
Start Free TrialLog in
Avatar of liudan
liudan

asked on

How to access outlook folders ,items and fields from Visual Basic ??

How to access Outlook folders, items and fields from Visual Basic?? :-)
Avatar of Cimperiali
Cimperiali
Flag of Italy image

For example...
'reference msoutl85.olb
Private objOutlook As Outlook.Application
Dim objMapi As NameSpace
Dim curInbox As Outlook.MAPIFolder
Dim MailItem As Variant 'needed as not all items are of "MailItem" type...
'.....
Screen.MousePointer = vbHourglass
'....Instance to OutLook
Set objOutlook = New Outlook.Application
'....INstance namespace
Set objMapi = objOutlook.GetNamespace("MAPI")
'..start getting inbox folder:
Set curInbox = objMapi.GetDefaultFolder(6)
'...get mails
For Each MailItem In curInbox.Items
   DoEvents 'you mau have a lot...do not hang pgm
   If TypeOf MailItem Is Outlook.MailItem Then
      'This is a mailitem. You can for example, get the subject
      'Here we add it to a listBox control
      'in conjunction with the EntryId of the mail, to be able to
      'reach the item when needed with a single shot
      List1.AddItem MailItem.EntryID & " " & MailItem.Subject
    ElseIf TypeOf MailItem Is Outlook.MeetingItem Then
      'This is a "Meeting Item". It has some fields less
      'you can retrieve the subject in any case, and here
      'we add it to another listBox control:  
      List2.AddItem "Meeting Item: " & MailItem.Subject
      MailItem.Close olDiscard
    End If
 
Next MailItem
Set MailItem = Nothing
Set curInbox = Nothing
Set objMapi = Nothing
objOutlook.Quit
Set objOutlook = Nothing
Screen.MousePointer = vbDefault
Avatar of liudan
liudan

ASKER

NO,I will access Outlook folders, items and fields from Visual Basic Without "MAPI".  :-)
With Cdo or Cdonts?...but I am not sure you can gain access to Outlook folders and items this way. You could parse a *.pst file, but it may not be one on client machine, as the items may still be on a server...
liudan:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
Avatar of DanRollins
Moderator, my recommended disposition is:

    Save as PAQ -- No Refund.

DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
Avatar of YensidMod
YensidMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial