2017-09-10 93 views
1

我想知道是否有方法比較ALL TITLES in ALL RSS FEEDS並刪除重複項。如何比較所有RSS提要的所有標題並刪除重複項?

我讀了很多RSS Feed,很明顯,很多人都在多個論壇交叉發帖,然後我多次看到相同的RSS Feed。

我覺得劇本會是這個樣子,但它似乎並沒有刪除受騙者.....

Option Explicit 
Public Sub DupeRSS() 
    Dim olNs As Outlook.NameSpace 
    Dim RSS_Folder As Outlook.MAPIFolder 

    Set olNs = Application.GetNamespace("MAPI") 
    Set RSS_Folder = olNs.GetDefaultFolder(olFolderRssFeeds) 

    'Process Current Folder 
    Example RSS_Folder 
End Sub 
Public Sub Example(ByVal ParentFolder As Outlook.MAPIFolder) 
    Dim itm As Object, itms As Items, dupes As Object, i As Long, k As Variant 

    Set dupes = CreateObject("Scripting.Dictionary") 
    Set itms = ParentFolder.Items 

    For i = itms.Folders.Count To 1 Step -1 
     Set itm = itms(i) 
     If TypeOf itm Is PostItem Then 
      If dupes.Exists(itm.Subject) Then itm.Delete Else dupes(itm.Subject) = 0 
     Else 
      Example itm  'Recursive call for Folders 
     End If 
    Next i 

    'Show dictionary items 
    If dupes.Count > 0 Then 
     For Each k In dupes 
      Debug.Print k 
     Next 
    End If 

    Set itm = Nothing: Set itms = Nothing: Set dupes = Nothing 
End Sub 

enter image description here

感謝所有!

回答

1

看起來像我(前Dim Items As Items。)誤解你對你以前question

也許這就是你要做的,下面的代碼保存/添加的所有項目主題行的集合,然後繼續查找多個文件夾,然後如果發現duplicates-刪除

Option Explicit 
Public Sub DupeRSS() 
    Dim olNs As Outlook.NameSpace 
    Dim RSS_Folder As Outlook.MAPIFolder 
    Dim DupItem As Object 

    Set DupItem = CreateObject("Scripting.Dictionary") 
    Set olNs = Application.GetNamespace("MAPI") 
    Set RSS_Folder = olNs.GetDefaultFolder(olFolderRssFeeds) 

' // Process Current Folder 
    Example RSS_Folder, DupItem 
End Sub 
Public Sub Example(ByVal ParentFolder As Outlook.MAPIFolder, _ 
        ByVal DupItem As Object) 
    Dim Folder As Outlook.MAPIFolder 
    Dim Item As Object 
    Dim Items As Items 
    Dim i As Long 

    Set Items = ParentFolder.Items 
    Debug.Print ParentFolder.Name 

    For i = Items.Count To 1 Step -1 
     DoEvents 

     If TypeOf Items(i) Is PostItem Then 
      Set Item = Items(i) 
      If DupItem.Exists(Item.Subject) Then 
       Debug.Print Item.Subject ' Print on Immediate Window 
       Debug.Print TypeName(Item) ' Print on Immediate Window 
       Item.Delete 
      Else 
       DupItem.Add Item.Subject, 0 
       Debug.Print DupItem.Count, Item.Subject 
      End If 
     End If 

    Next i 

' // Recurse through subfolders 
    If ParentFolder.Folders.Count > 0 Then 
     For Each Folder In ParentFolder.Folders 
      Example Folder, DupItem 
      Debug.Print Folder.Name 
     Next 
    End If 

    Set Folder = Nothing 
    Set Item = Nothing 
    Set Items = Nothing 
End Sub 
+1

Ahhhhhh!這是一件美麗的事情!這正是我想要的!非常感謝!! – ryguy72

0

嘗試改變波紋管


Option Explicit 

'Required - VBA Editor -> Tools -> References: Microsfot Outlook XXX Object Library 
'Required - VBA Editor -> Tools -> References: Microsfot Scripting Runtime (Dictionary) 

Public Sub RemoveRSSduplicates() 
    Dim olNs As Outlook.Namespace, olApp As Object, rssFolder As Folder, d As Dictionary 

    Set olApp = GetObject(, "Outlook.Application") 
    Set olNs = olApp.GetNamespace("MAPI") 
    Set rssFolder = olNs.GetDefaultFolder(olFolderRssFeeds) 
    Set d = CreateObject("Scripting.Dictionary") 

    ProcessOutlookRSSFeeds rssFolder, d 
End Sub 

Public Sub ProcessOutlookRSSFeeds(ByVal rssFolder As Folder, ByRef d As Dictionary) 
    Dim fldr As Folder, itm As Object 

    For Each fldr In rssFolder.Folders 
     If fldr.Items.Count > 0 Then 
      For Each itm In fldr.Items 
       If TypeOf itm Is PostItem Then 
        If Not d.Exists(itm.Subject) Then d(itm.Subject) = 0 Else itm.Delete 
       End If 
      Next 
     End If 
    Next 
End Sub 

注意:避免變量名,將隱藏其他對象

+0

這很奇怪。現在,我在這一行上得到一個錯誤:For i = itms.Folders.Count To 1 Step -1。錯誤消息顯示爲:Object不支持此屬性或方法。我只是更新了現在的所有代碼。 – ryguy72

+1

它似乎是循環遍歷所有文件夾和每個文件夾中的所有主題,但只要焦點從一個文件夾移動到下一個文件夾,先前文件夾中的所有主題都將丟失,因此這絕不會找到任何重複。我認爲這是最初的問題,現在看來也是一樣。啊。任何其他想法?謝謝。 – ryguy72

相關問題