View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Tim Zych[_2_] Tim Zych[_2_] is offline
external usenet poster
 
Posts: 41
Default retreiving number of e-mails from public folder in Outlook, next step

Well, on my machine this approach worked:

Set Fldr = olNs.Folders("Personal Folders").Folders("My Folder")
Debug.Print Fldr.Name & " has " & Fldr.Items.Count & " items"

I don't have the Exchange environment here, but you should be able to
"drill" down into as many folders as you need.

Yours may end up being something along the lines of:

Set Fldr = olNs.Folders("Public Folders").Folders("All Public Folders"). _
Folders("My Folder")


"Barmaley" wrote in message
...
With the help of Dick Kusleika and Chip Pearson I have managed to arrive

to
this code, which checks e-mails in InBox. I couldn't figuire out how to
change
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
to extract e-mail info from Public Folder that reside on Exchange server.
Folder structure looks like this:
"Public Folders-All Public Folders-Custom Folder" etc (it has couple

more
subfolders)

Can anyone help me please?


Sub GetFromInbox2()
Dim olApp As Outlook.Application
Dim olNs As NameSpace
Dim Fldr As MAPIFolder
Dim olMail As Variant
Dim i As Integer

Set olApp = New Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
Set Fldr = olNs.GetDefaultFolder(olFolderInbox)
i = 1

For Each olMail In Fldr.Items
If InStr(olMail.ReceivedTime, Range("F1")) 0 Then
ActiveSheet.Cells(i, 1).Value = olMail.ReceivedTime
i = i + 1
End If
Next olMail

Set Fldr = Nothing
Set olNs = Nothing
Set olApp = Nothing
End Sub