0

I tried to write a script, that counts the e-Mails in a specific public exchange folder in outlook. If there are Mails in subfolder2, a Messagebox should open and tell me, how many Mails there are. I tried this, but it did not work.

    Outlook := ComObjActive("Outlook.Application")
    mail = (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder\Subfolder2")
    if (mail.Items.Count>0)
    {
    msgbox % mail.Items.Count "Mails in folder"
    }
    else
    {
    msgbox No Mails.
    }

Does anyone has a idea, how I should change the script, that it works?

PHS
  • 11
  • 1
  • 4

3 Answers3

0

Please try to use this:

mail := Outlook.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder\Subfolder2")

  • sadly, it did not work. I still get the "else", although there are mails in the folder. – PHS Nov 14 '18 at 14:47
0

You must retrieve subfoldersone at a time, you cannot specify a path. Change the line

 mail = (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder\Subfolder2")

to

 mail = (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder").Folders("Subfolder2")
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
0

I got it. I simply removed the Variable.

 Outlook := ComObjActive("Outlook.Application")
    if (Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder").Folders("Subfolder2").Items.Count>0)
    {
    msgbox % Outlook.Application.ActiveExplorer().Session.GetDefaultFolder(18).Folders("Subfolder").Folders("Subfolder2").Items.Count "Mails in folder"
    }
    else
    {
    msgbox No Mails.
    }

Thanks for the help :D

PHS
  • 11
  • 1
  • 4