Open email in specific folder

2019-09-10 11:04发布

I'm having issues accessing emails in a specific folder within Outlook.

When I put the emails in the Inbox, the following line of code works.

Set OtlkApp = GetObject(, "Outlook.application")
Set ns = OtlkApp.GetNamespace("MAPI")
Set fldr = ns.GetDefaultFolder(olFolderInbox)

However, when I try to access a folder called "tempfiles", it could not find the object when I tried opening it using this code.

Set fldr = ns.Folders("tempfiles")

Is the syntax correct? Am I missing something?

1条回答
做个烂人
2楼-- · 2019-09-10 11:26

Depending on the level of tempfolders (same level or subfolder of Inbox) you extend the folders property:

'INBOX FOLDER
Set inboxfldr = ns.GetDefaultFolder(olFolderInbox)

'TEMPFILES SUBFOLDER
Set tempfilesfldr = inboxfldr.Folders("tempfiles")

'TEMPFILES FOLDER (SAME LEVEL AS DEFAULT FOLDERS -INBOX, CALENDAR, TASKS, ETC.)
Set tempfilesfldr = inboxfldr.Parent.Folders("tempfiles")
查看更多
登录 后发表回答