2010-02-20 4 views
1

Outlook 2007 폴더에서 CSV 파일로 메일을 내보내는 가장 좋은 방법은 무엇입니까? 하위 폴더에도 메일 메시지를 포함시키고 싶습니다. 내장 된 csv 익스포터는 하위 폴더를 포함하는 옵션을 허용하지 않지만, 그렇지 않으면 내가 원하는 것을 정확하게 수행합니다.Outlook 2007의 메일 폴더 및 하위 폴더를 CSV로 내보내기

답변

2

Office 자동화가 여기에있는 방법이라고 할 수 있습니다. Excel이 설치되어있는 경우 속성을 워크 시트의 셀에 직접 삽입 할 수 있습니다. Excel에서 매크로를 작성하여 Outlook을 자동화하거나 Outlook에 매크로를 작성하여 데이터를 워크 시트로 푸시 할 수 있습니다. 나는 전망에 대한 VBA의 빠른 조각을 만들어 대신 더러운 일을하는 FSO를 사용하고 아래

, 그것은 당신이 등을 테스트

을 처리하는 더 많은 오류가 필요합니다 에서 일할 수있는 골격을 줄 것이다
Sub SaveItemsToExcel() 

    On Error GoTo ErrorHandlerExit 


    Dim oNameSpace As Outlook.NameSpace 
    Dim oFolder As Outlook.MAPIFolder 
    'You must set a reference to the Microsoft Scripting Runtime library touse the FileSystemObject 

    Dim objFS As Scripting.FileSystemObject 
    Dim objOutputFile As Scripting.TextStream 

    Set objFS = New Scripting.FileSystemObject 
    Set objOutputFile = objFS.OpenTextFile("C:\Temp\Export.csv", ForWriting, True) 
    Set oNameSpace = Application.GetNamespace("MAPI") 
    Set oFolder = oNameSpace.PickFolder 

    If oFolder Is Nothing Then 
     GoTo ErrorHandlerExit 
    End If 


    ' Check if folder can contain Mail Items 
    If oFolder.DefaultItemType <> olMailItem Then 
     MsgBox "Folder does not contain mail messages" 
     GoTo ErrorHandlerExit 
    End If 


    'Write header line 
    objOutputFile.WriteLine "From,Subject,Recived" 

    ProcessFolderItems oFolder, objOutputFile 

    objOutputFile.Close 

    Set oFolder = Nothing 
    Set oNameSpace = Nothing 
    Set objOutputFile = Nothing 
    Set objFS = Nothing 

ErrorHandlerExit: 
    Exit Sub 


End Sub 

Sub ProcessFolderItems(oParentFolder As Outlook.MAPIFolder, ByRef objOutputFile As Scripting.TextStream) 
    Dim oCount As Integer 
    Dim oMail As Outlook.MailItem 
    Dim oFolder As Outlook.MAPIFolder 
    oCount = oParentFolder.Items.Count 

    For Each oMail In oParentFolder.Items 
     If oMail.Class = olMail Then 

     objOutputFile.WriteLine oMail.SenderEmailAddress & "," & oMail.Subject & "," & oMail.ReceivedTime 

     End If 
    Next oMail 

    Set oMail = Nothing 
    'check to see if we have an child folders 
    If (oParentFolder.Folders.Count > 0) Then 
      For Each oFolder In oParentFolder.Folders 
       ProcessFolderItems oFolder, objOutputFile 
      Next 
    End If 


End Sub 

마커스

+0

마커스,이 스크립트를 제공해 주셔서 감사합니다! 첫 번째 시도에서 완벽하게 작동했습니다. 내가해야 할 유일한 변화는 쉼표가있는 항목을 쉼표로 사용했기 때문에 필드에서 쉼표를 제거하는 것이 었습니다. 다른 필드에 액세스 할 수 있도록 MailItem 개체를 보았습니다. 대단히 고마워요, 당신은 저에게 이걸 알아내는 데 많은 시간을 아끼 셨습니다! – Noel

+0

Btw, 정말 하드 대신 스크립트로 그것을 코딩 폴더를 선택할 수있는 기능을 좋아해 :) – Noel