从Outlook中的特定文件夹导入电子邮件 [英] Import Emails from specific folder in Outlook

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

问题描述

我当前在Excel中使用以下代码访问除我自己以外的无人值守邮箱中的文件夹.

I'm currently using the following code in Excel to access folders in an unmanned Outlook mailbox other than my own.

但是,有一种方法可以在代码中设置文件夹,而不是使用文件夹选择器.

However is there a way I can set the folder in the code rather than using the folder picker.

Sub Launch_Pad()   
Dim olApp As Outlook.Application
Dim olNS As Outlook.Namespace
Dim olFolder As Outlook.MAPIFolder

Set olApp = Outlook.Application
Set olNS = olApp.GetNamespace("MAPI")
Set olFolder = olNS.PickFolder

n = 2
Cells.ClearContents

Call ProcessFolder(olFolder)

Set olNS = Nothing
Set olFolder = Nothing
Set olApp = Nothing
Set olNS = Nothing
End Sub

Sub ProcessFolder(olfdStart As Outlook.MAPIFolder)

Dim olFolder As Outlook.MAPIFolder
Dim olObject As Object
Dim olMail As Outlook.MailItem
   n = 1
For Each olObject In olfdStart.Items
    If TypeName(olObject) = "MailItem" Then

        n = n + 1
        Set olMail = olObject
            Cells(n, 1) = olMail.Subject
            Cells(n, 2) = olMail.ReceivedTime
            Cells(n, 3) = olMail.Body

    End If
Next
Set olMail = Nothing
Set olFolder = Nothing
Set olObject = Nothing
End Sub

推荐答案

感谢Erdem

Sub ShareMail()

    Dim olNamespace As Outlook.Namespace
    Dim olApp As Outlook.Application
    Dim olNs As Outlook.Namespace
    Dim olFolder As Outlook.MAPIFolder
    Dim olRecip As Outlook.Recipient

    Set olApp = Outlook.Application
    Set olNs = olApp.GetNamespace("MAPI")
    Set olRecip = olNs.CreateRecipient("mail@mail.com")
    Set olFolder = olNs.GetSharedDefaultFolder(olRecip, olFolderInbox).Folders("myfolder")

   Call ProcessFolder(olFolder)

    Set olApp = Nothing
    Set olNs = Nothing
    Set olRecip = Nothing
    Set olFolder = Nothing


End Sub

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

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