使用Visual Basic访问收件箱中的子文件夹? [英] Using visual basic to access subfolder in Inbox?

查看:90
本文介绍了使用Visual Basic访问收件箱中的子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set myOlItems = objNS.GetDefaultFolder(olFolderInbox).Items

我已经使用上面的代码访问了Outlook的主要收件箱,但是如何使用vba访问收件箱中的文件夹及其邮件!

I have used the code above to access the main outlook Inbox but how to access the folders in inbox and it's mail using vba!

推荐答案

那非常接近:)

要获取收件箱下名为"temp"的文件夹中的所有邮件,请尝试

To get all the mail items in a folder called "temp" under the Inbox try this

Dim olApp As Outlook.Application
Dim objNS As Outlook.NameSpace
Dim olFolder As Outlook.MAPIFolder
Dim msg As Outlook.MailItem

Set olApp = Outlook.Application
Set objNS = olApp.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox)
Set olFolder = olFolder.Folders("Temp")

For Each msg In olFolder.Items
    Debug.Print msg.Subject
Next

这篇关于使用Visual Basic访问收件箱中的子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆