遍历特定Outlook文件夹中的所有电子邮件项目 [英] Iterate all email items in a specific Outlook folder

查看:92
本文介绍了遍历特定Outlook文件夹中的所有电子邮件项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Outlook VBA宏中迭代特定Outlook文件夹中的所有电子邮件项目(在这种情况下,该文件夹不属于我的个人收件箱,而是共享邮箱的收件箱的子文件夹.

How can I in an Outlook VBA macro iterate all email items in a specific Outlook folder (in this case the folder belongs not to my personal inbux but is a sub-folder to the inbox of a shared mailbox.

类似这样的东西,但我从未做过Outlook宏...

Something like this but I've never done an Outlook macro...

For each email item in mailboxX.inbox.mySubfolder.items
// do this
next item

我尝试了此操作,但是找不到收件箱子文件夹...

I tried this but the inbox subfolder is not found...

Private Sub Application_Startup()

Dim objNS As Outlook.NameSpace
Dim objFolder As Outlook.MAPIFolder
Set objNS = GetNamespace("MAPI")
Set objFolder = objNS.Folders("myGroupMailbox")
Set objFolder = objFolder.Folders("Inbox\mySubFolder1\mySubFolder2")

  On Error GoTo ErrorHandler
  Dim Msg As Outlook.MailItem

For Each Item In objFolder.Items

  If TypeName(Item) = "MailItem" Then

    Set Msg = Item
    If new_msg.Subject Like "*myString*" Then
        strBody = myItem.Body
        Dim filePath As String
        filePath = "C:\myFolder\test.txt"
        Open filePath For Output As #2
        Write #2, strBody
        Close #2

    End If

  End If

ProgramExit:
  Exit Sub
ErrorHandler:
  MsgBox Err.Number & " - " & Err.Description
  Resume ProgramExit

Next Item

End Sub

推荐答案

格式为:

Set objFolder = objFolder.Folders("Inbox").Folders("mySubFolder1").Folders("mySubFolder2")

如在注释中建议的那样将下一个项目行移至ProgramExit标签之前"

As advised in a comment "move the next item line to before the ProgramExit label"

这篇关于遍历特定Outlook文件夹中的所有电子邮件项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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