2017-04-07 2 views
1

현재 Excel에서 다음 코드를 사용하여 내 자신 이외의 무인 Outlook 사서함에있는 폴더에 액세스하고 있습니다.Outlook의 특정 폴더에서 전자 메일 가져 오기

그러나 폴더 선택기를 사용하는 대신 코드에서 폴더를 설정할 수있는 방법이 있습니다.

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 

답변

1

폴더가 당신이

Set olFolder = olNS.GetDefaultFolder(olFolderInbox) 

이하 또는 하위 폴더에 사용할 수있는받은 편지함해야하는 경우

Set olFolder = olNS.GetDefaultFolder(olFolderInbox).Folders("mysubfolder") 
+0

감사하지만, 자신의받은 편지함 폴더에하지면 내 자신의 –

+1

시도'설정 olFolder = olNs.GetSharedDefaultFolder (olRecip, olFolderInbox을 따라 나열된 다른 사서함이 유일한 작품). 폴더 ("mysubfolder")'? –

1

하나 다른 사용자에 대한 액세스 권한을 얻는 GetSharedDefaultFolder Method과 협력 또는 더 많은 기본 폴더. 여기

GetSharedDefaultFolder Method 지정된 사용자에 대해 지정된 기본 폴더를 나타내는 MAPIFolder 오브젝트를 돌려받은 편지함

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("[email protected]") 
Set olFolder = olNs.GetSharedDefaultFolder(olRecip, olFolderInbox) 

Or 

Set olFolder = olNs.GetSharedDefaultFolder(olRecip, olFolderInbox).Folders("SubfolderName") 

을 공유됩니다. 이 메서드는 한 명 이상의 사용자가 기본 폴더 (예 : 공유 일정 폴더) 중 하나 이상에 대해 다른 사용자에게 액세스 권한을 위임 한 위임 시나리오에서 사용됩니다.

+0

Thx,받은 편지함에 액세스 할 수 있지만 보조 폴더에 액세스하는 방법 –

+0

@kdawg 기억해 주시기 바랍니다. https://meta.stackexchange.com/a/5235/289619 – 0m3r

2

감사 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("[email protected]") 
    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 
관련 문제