R
Reiner
Hi,
I try to write a macro that deletes double (and more) emails. Take a
look on the code (you can input a folder structure with up to three
folders).
----------------------------------------------------------------
Sub DoppelteLoeschen()
Dim olNameSpace As NameSpace
Dim olInputBox As MAPIFolder
Dim olFolderInbox As MAPIFolder
Dim olFolderSent As MAPIFolder
Dim InboxItems As Outlook.MailItem
Dim ItemSearch As Outlook.MailItem
Dim ItemFound As Outlook.MailItem
Dim ItemsToSearch As Outlook.Items
Dim ItemsRestricted As Outlook.Items
Dim bDoNext As Boolean
Dim intMails As Integer, i As Integer, j As Integer
Dim szMajorFolder, szText, szTitle, szDefault, szFolder As String,
szSubFolder As String
Dim deInDate1 As Date, deSendDate1 As Date, szSenderName1 As String,
szSubject1 As String
Dim deInDate2 As Date, deSendDate2 As Date, szSenderName2 As String,
szSubject2 As String
On Error Resume Next
Set olNameSpace = Application.GetNamespace("MAPI")
szMajorFolder = "Reiner"
szTitle = "Ordnerbestimmung"
szDefault = "Reiner"
szText = "Bitte geben Sie den Namen des Hauptordners unter
<Persönliche Ordner> ein."
szMajorFolder = InputBox(szText, szTitle, szDefault)
If Len(szMajorFolder) = 0 Then
szMajorFolder = "Reiner"
End If
szDefault = ""
szText = "Bitte geben Sie den Namen des zu bearbeitenden Ordners
unter " + szMajorFolder + " ein."
szFolder = InputBox(szText, szTitle, szDefault)
If szFolder = "ENDE" Then
i = MsgBox("Makro ohne Aktion beendet", vbOKOnly, "Makro
beendet")
Exit Sub
End If
If Len(szFolder) > 0 Then
szDefault = ""
szText = "Bitte geben Sie den Namen des zu bearbeitenden Ordners
unter " + szMajorFolder + " und " + szFolder + " ein."
szSubFolder = InputBox(szText, szTitle, szDefault)
If szSubFolder = "ENDE" Then
i = MsgBox("Makro ohne Aktion beendet", vbOKOnly, "Makro
beendet")
Exit Sub
End If
End If
If szMajorFolder = "Posteingang" Then
Set olInputBox = olNameSpace.GetDefaultFolder(olFolderInbox)
ElseIf szMajorFolder = "Gesendete Objekte" Then
Set olInputBox = olNameSpace.GetDefaultFolder(olFolderSent)
ElseIf Len(szFolder) = 0 Then
Set olInputBox =
Application.GetNamespace("MAPI").Folders("Persönliche
Ordner").Folders(szMajorFolder)
ElseIf Len(szSubFolder) = 0 Then
Set olInputBox =
Application.GetNamespace("MAPI").Folders("Persönliche
Ordner").Folders(szMajorFolder).Folders(szFolder)
Else
Set olInputBox =
Application.GetNamespace("MAPI").Folders("Persönliche
Ordner").Folders(szMajorFolder).Folders(szFolder).Folders(szSubFolder)
End If
'olInputBox.Items.Sort "[SentOn]" + "[Subject]" + "[SenderName]",
True
olInputBox.Items.Sort "[SentOn]", False
Dim sFilter As String
iCount = olInputBox.Items.Count
Dim sNothing As String
sNothing = "Nothing"
Set ItemsToSearch = olInputBox.Items
For Each ItemSearch In olInputBox.Items
With ItemSearch
deInDate1 = .ReceivedTime
deSendDate1 = .SentOn
szSenderName1 = .SenderName
szSubject1 = .Subject
' sFilter = "[ReceivedTime] = '" & Format(.ReceivedTime,
"yyyymmddhhmmss") & "' And [SentOn] = '" _
' & Format(.SentOn, "yyyymmddhhmmss") & "' And
[SenderName] = '" & .SenderName _
' & "' And [Subject] = '" & .Subject & "'"
' No seconds allowed?
sFilter = "[ReceivedTime] = '" & Format(.ReceivedTime,
"yyyymmddhhmm") & "' And [SentOn] = '" _
& Format(.SentOn, "yyyymmddhhmm") & "' And
[SenderName] = '" & .SenderName _
& "' And [Subject] = '" & .Subject & "'"
sFilter = "[Subject] = 'Projektangebote ID Netz'"
End With
'ItemFound = olInputBox.Items.Find(sFilter)
ItemFound = ItemsToSearch.Find(sFilter)
ItemsRestricted = olInputBox.Items.Restrict(sFilter)
While TypeName(ItemFound) <> sNothing
If ItemFound.EntryID <> ItemSearch.EntryID Then
ItemFound.Delete
End If
'ItemFound = olInputBox.Items.FindNext
ItemFound = ItemsToSearch.FindNext
Wend
Next ItemSearch
End Sub
----------------------------------------------------------------
The problem is that the items of olInputBox (seen at the Watcher) are
all empty. In "Item X" you can read "<No Variables>". But ItemSearch is
not empty.
Does anybody knows what's wrong with my code?
Asking greetings
Reiner
I try to write a macro that deletes double (and more) emails. Take a
look on the code (you can input a folder structure with up to three
folders).
----------------------------------------------------------------
Sub DoppelteLoeschen()
Dim olNameSpace As NameSpace
Dim olInputBox As MAPIFolder
Dim olFolderInbox As MAPIFolder
Dim olFolderSent As MAPIFolder
Dim InboxItems As Outlook.MailItem
Dim ItemSearch As Outlook.MailItem
Dim ItemFound As Outlook.MailItem
Dim ItemsToSearch As Outlook.Items
Dim ItemsRestricted As Outlook.Items
Dim bDoNext As Boolean
Dim intMails As Integer, i As Integer, j As Integer
Dim szMajorFolder, szText, szTitle, szDefault, szFolder As String,
szSubFolder As String
Dim deInDate1 As Date, deSendDate1 As Date, szSenderName1 As String,
szSubject1 As String
Dim deInDate2 As Date, deSendDate2 As Date, szSenderName2 As String,
szSubject2 As String
On Error Resume Next
Set olNameSpace = Application.GetNamespace("MAPI")
szMajorFolder = "Reiner"
szTitle = "Ordnerbestimmung"
szDefault = "Reiner"
szText = "Bitte geben Sie den Namen des Hauptordners unter
<Persönliche Ordner> ein."
szMajorFolder = InputBox(szText, szTitle, szDefault)
If Len(szMajorFolder) = 0 Then
szMajorFolder = "Reiner"
End If
szDefault = ""
szText = "Bitte geben Sie den Namen des zu bearbeitenden Ordners
unter " + szMajorFolder + " ein."
szFolder = InputBox(szText, szTitle, szDefault)
If szFolder = "ENDE" Then
i = MsgBox("Makro ohne Aktion beendet", vbOKOnly, "Makro
beendet")
Exit Sub
End If
If Len(szFolder) > 0 Then
szDefault = ""
szText = "Bitte geben Sie den Namen des zu bearbeitenden Ordners
unter " + szMajorFolder + " und " + szFolder + " ein."
szSubFolder = InputBox(szText, szTitle, szDefault)
If szSubFolder = "ENDE" Then
i = MsgBox("Makro ohne Aktion beendet", vbOKOnly, "Makro
beendet")
Exit Sub
End If
End If
If szMajorFolder = "Posteingang" Then
Set olInputBox = olNameSpace.GetDefaultFolder(olFolderInbox)
ElseIf szMajorFolder = "Gesendete Objekte" Then
Set olInputBox = olNameSpace.GetDefaultFolder(olFolderSent)
ElseIf Len(szFolder) = 0 Then
Set olInputBox =
Application.GetNamespace("MAPI").Folders("Persönliche
Ordner").Folders(szMajorFolder)
ElseIf Len(szSubFolder) = 0 Then
Set olInputBox =
Application.GetNamespace("MAPI").Folders("Persönliche
Ordner").Folders(szMajorFolder).Folders(szFolder)
Else
Set olInputBox =
Application.GetNamespace("MAPI").Folders("Persönliche
Ordner").Folders(szMajorFolder).Folders(szFolder).Folders(szSubFolder)
End If
'olInputBox.Items.Sort "[SentOn]" + "[Subject]" + "[SenderName]",
True
olInputBox.Items.Sort "[SentOn]", False
Dim sFilter As String
iCount = olInputBox.Items.Count
Dim sNothing As String
sNothing = "Nothing"
Set ItemsToSearch = olInputBox.Items
For Each ItemSearch In olInputBox.Items
With ItemSearch
deInDate1 = .ReceivedTime
deSendDate1 = .SentOn
szSenderName1 = .SenderName
szSubject1 = .Subject
' sFilter = "[ReceivedTime] = '" & Format(.ReceivedTime,
"yyyymmddhhmmss") & "' And [SentOn] = '" _
' & Format(.SentOn, "yyyymmddhhmmss") & "' And
[SenderName] = '" & .SenderName _
' & "' And [Subject] = '" & .Subject & "'"
' No seconds allowed?
sFilter = "[ReceivedTime] = '" & Format(.ReceivedTime,
"yyyymmddhhmm") & "' And [SentOn] = '" _
& Format(.SentOn, "yyyymmddhhmm") & "' And
[SenderName] = '" & .SenderName _
& "' And [Subject] = '" & .Subject & "'"
sFilter = "[Subject] = 'Projektangebote ID Netz'"
End With
'ItemFound = olInputBox.Items.Find(sFilter)
ItemFound = ItemsToSearch.Find(sFilter)
ItemsRestricted = olInputBox.Items.Restrict(sFilter)
While TypeName(ItemFound) <> sNothing
If ItemFound.EntryID <> ItemSearch.EntryID Then
ItemFound.Delete
End If
'ItemFound = olInputBox.Items.FindNext
ItemFound = ItemsToSearch.FindNext
Wend
Next ItemSearch
End Sub
----------------------------------------------------------------
The problem is that the items of olInputBox (seen at the Watcher) are
all empty. In "Item X" you can read "<No Variables>". But ItemSearch is
not empty.
Does anybody knows what's wrong with my code?
Asking greetings
Reiner