Link to home
Start Free TrialLog in
Avatar of JohnPell
JohnPellFlag for United States of America

asked on

How do I check for an outlook folder and create it if it does not exist?

Hello, I would like to write a VB Script to be able to check for a folder in Outlook, Under the users mailbox, (Pelletier, John - Mailbox) and if it does not exist, create it.
Avatar of RobSampson
RobSampson
Flag of Australia image

There's a few examples here, although I don't use Outlook, but outlookcode.com is a great place to look for such a thing:
http://www.outlookcode.com/threads.aspx?forumid=5&messageid=7923
http://www.outlookcode.com/d/code/quarexe.htm

Regards,

Rob.
Avatar of JohnPell

ASKER

Thanks for the response, however these examples are in VBA and don't really cover what I need.
What language do you need it in, and what are the exact steps you need to cover?

Rob.
VB Script, found something from "The Scripting Guy" and wrote the below, which works.

Const olFolderInbox = 6

    Set objOutlook = CreateObject("Outlook.Application")
    Set objNamespace = objOutlook.GetNamespace("MAPI")
    Set objFolder = objNamespace.GetDefaultFolder(olFolderInbox)

    strFolderName = objFolder.Parent
    Set objMailbox = objNamespace.Folders(strFolderName)
    On Error Resume Next 'Mailbox already exists
    Set objNewFolder = objMailbox.Folders.Add("ImportToCall")
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

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
I really appreciate your taking the time to answer!
No worries.  Thanks JohnPell.

Rob.