2013-04-25 13 views
1

我們的防火牆用戶發送請求解除阻止某些他們認爲不應阻止的網站的郵件。他們的郵件主題字段包含這樣的網站網址。實際上,每個消息都會發送一個url。由於用戶數量的增加,預計每天會收到數百或數千條消息。Outlook宏將衆多郵件的「主題字段」中的數據收集/提取到文本文件

是否有一個Outlook宏將收集或提取這樣的網址(從收到的郵件主題字段)到一個單一的文本文件,而不必打開任何消息?

深切感謝您對此事的任何幫助。

在此先感謝

+0

什麼應該觸發此「檢索」操作?哪個附加參數應該決定你想要'這個電子郵件主題',而不是'另一個' - 主題中的任何關鍵字,你發送這些電子郵件的任何文件夾,任何收件人的地址? – 2013-04-25 22:02:06

+0

當然..首先,檢索動作將在其他工作負荷時手動觸發。其次,「http://」和「分類在:」在主題字段中都是關鍵的「詞語」,它們被用作參數來選擇他們的消息而不是另一個。第三,檢索操作針對在MS Outlook上查看和管理的[email protected]帳戶的收件箱中的收到消息運行。檢索操作預計會產生一個簡單的文本文件,其中收集主題字段中的數據(檢索操作)之前會刪除已處理的郵件。希望這是有道理的! – 2013-04-25 22:50:15

回答

3

請將此代碼寫入您的Outlook VBA模塊。在下面的一些行中更改一些文件夾和目標文件的名稱。有關其他信息,請參閱子內的註釋。

Sub Retrieve_http() 

'our Outlook folder- deifinitions 
    Dim myItem As MailItem 
    Dim myFolder As Folder 
    Dim myNamespace As NameSpace 
    Set myNamespace = Application.GetNamespace("MAPI") 
    'put your folders name here 
    '1st one is store folder which should refer to [email protected] 
    'second is possibly 'inbox folder' 
    Set myFolder = myNamespace.folders("[email protected]").folders("inbox") 

'destination file 
    Dim resFile As String 
     resFile = "c:\Users\Kazik\Desktop\httpRequest.txt" 
    Dim ff As Byte 
     ff = FreeFile() 
    'creating or opening it- each time you run this macro we will append data 
    'until deletion of either file or its content 
    Open resFile For Append As #ff 

    For Each myItem In myFolder.items 
     If InStr(1, myItem.Subject, "http://") > 0 And _ 
      InStr(1, myItem.Subject, "classified under:") > 0 Then 
       'write to file 
       Write #ff, myItem.Subject 

     End If 
    Next 
    Close #ff 
End Sub 

EDIT以包括適當的刪除處理和代碼的圖片的參考。

下圖顯示了Outlook窗口(波蘭語版)其中:Business Mail是「頂級文件夾」(指單獨的.pst文件)之一。 'Skrzynka odbiorcza'只是'收件箱'。其搜索某些電子郵件

enter image description here

代碼,檢索主題的電子郵件,並刪除郵件之後看起來如下:

Sub Retrieve_http() 

'our Outlook folder- deifinitions 
    Dim myItem As MailItem 
    Dim myFolder As Folder 
    Dim myNamespace As NameSpace 
    Set myNamespace = Application.GetNamespace("MAPI") 
    'put your folders name here 
    Set myFolder = myNamespace.folders("Business Mail").folders("skrzynka odbiorcza") 

'destination file 
    Dim resFile As String 
     resFile = "c:\Users\Kazik\Desktop\httpRequest.txt" 
    Dim ff As Byte 
     ff = FreeFile() 
    'creating or opening it- each time you run this macro we will append data 
    'until deletion of either file or its content 
    Open resFile For Append As #ff 
    Dim i! 
    For i = myFolder.items.Count To 1 Step -1 
     If InStr(1, myFolder.items(i).Subject, "http://") > 0 And _ 
      InStr(1, myFolder.items(i).Subject, "classified under") > 0 Then 
       'write to file 
       Write #ff, myFolder.items(i).Subject 
       'delete item 
       myFolder.items(i).Delete 
     End If 
    Next 
    Close #ff 
End Sub 
+0

非常感謝Kazik爲您的專業及時性,生產這樣的傑作。不過,我仍然想知道這個代碼行:Set myFolder = myNamespace。文件夾(「[email protected]」)。文件夾(「收件箱」)是指第一個「文件夾」中的.pst文件?如果它是肯定的,我確實把我的路徑設置爲:「C:\ Users \ Josef Miller \ AppData \ Local \ Microsoft \ Outlook \(IUASS)Firewall Support.pst」並停止調試以突出顯示以前的代碼行。有什麼建議麼? – 2013-04-26 08:06:12

+0

我會說'是的,以某種方式'。 '.Folders(「[email protected]」)與'.pst'文件連接,但不能像你那樣設置引用。簡而言之:'.pst'是一個文件,你可以把它作爲一個文件來處理(我甚至不知道需要不同的邏輯)。 'myFolder'是對象,這意味着它將'.pst'轉換爲Outlook對象結構。如果您在設置對「myFolder」的引用時遇到任何問題,請嘗試使用名稱(或索引)。我在發帖之前檢查了代碼:) – 2013-04-26 08:42:41

+0

謝謝Kazik的回答,這實際上讓我花費了整整一天的時間在一個「試錯」過程中,最終沒有成功。我無法讓這段代碼適用於我,因爲我沒有指定或指向'.pst'文件夾。你的任何建議都非常重視我。感謝您。 – 2013-04-27 12:22:52

0

這裏是解決你的問題:)

當你製作一個For Each Outlook它枚舉每個電子郵件。 如果您在循環中移動任何電子郵件For Each,那麼Outlook會更改文件夾中所有電子郵件的數量,但不會更改循環的迭代數量。這會導致幾個不會被讀取的消息。

解決方案是從去年開始的電子郵件循環這裏提到 Outlook macro to collect/extract data from "Subject field" of numerous messages into a text file

CODE: 更換(每InboxMsg在Inbox.Items)與

對於i = Inbox.Items.Count到1步-1'從結尾向後迭代 Set InboxMsg = Inbox.Items(i)

相關問題