E
Eylon
Hello Everyone,
I wrote a Macro that takes the selected Email, removes some text from the
subject (e.g. “RE:, FW:†etc.) and performs a search on all Emails containing
this string. The results of the search are displayed in a new window.
Sometimes it works as expected, and sometimes I get an error:
This is how the error object holds these values:
Description: "The operation failed."
HelpContext: 1000440
Number: -2147219964
From when it fails, Instant search stops responding in the main window as
well. All this until I restart Outlook (2007).
Interestingly, when I change the Macro to display the results in the current
(main) window, it always work without any problem.
The code:
******************************
Sub SearchByStrippedSubject()
Dim app As New Outlook.Application
Dim item As Object
Dim email As MailItem
Set email = app.ActiveExplorer.Selection.item(1)
Dim myExplorer As Explorer
On Error Resume Next
Set myExplorer =
app.Explorers.Add(app.Session.GetDefaultFolder(olFolderInbox),
olFolderDisplayNormal)
Dim filter As String
filter = email.Subject
filter = Replace(filter, "RE: ", "")
filter = Replace(filter, "FW: ", "")
filter = Replace(filter, "RE:", "")
filter = Replace(filter, "FW:", "")
filter = Replace(filter, " (handled)", "")
filter = Replace(filter, "(handled)", "")
filter = Replace(filter, " (handling)", "")
filter = Replace(filter, "(handling)", "")
filter = Chr(34) + filter + Chr(34)
On Error Resume Next
myExplorer.Search filter, olSearchScopeAllFolders
If Err.Number <> 0 Then
MsgBox Err.Description
Err.Clear
myExplorer.Close
Exit Sub
End If
myExplorer.Display
End Sub
******************************
Any ideas?
TIA,
I wrote a Macro that takes the selected Email, removes some text from the
subject (e.g. “RE:, FW:†etc.) and performs a search on all Emails containing
this string. The results of the search are displayed in a new window.
Sometimes it works as expected, and sometimes I get an error:
This is how the error object holds these values:
Description: "The operation failed."
HelpContext: 1000440
Number: -2147219964
From when it fails, Instant search stops responding in the main window as
well. All this until I restart Outlook (2007).
Interestingly, when I change the Macro to display the results in the current
(main) window, it always work without any problem.
The code:
******************************
Sub SearchByStrippedSubject()
Dim app As New Outlook.Application
Dim item As Object
Dim email As MailItem
Set email = app.ActiveExplorer.Selection.item(1)
Dim myExplorer As Explorer
On Error Resume Next
Set myExplorer =
app.Explorers.Add(app.Session.GetDefaultFolder(olFolderInbox),
olFolderDisplayNormal)
Dim filter As String
filter = email.Subject
filter = Replace(filter, "RE: ", "")
filter = Replace(filter, "FW: ", "")
filter = Replace(filter, "RE:", "")
filter = Replace(filter, "FW:", "")
filter = Replace(filter, " (handled)", "")
filter = Replace(filter, "(handled)", "")
filter = Replace(filter, " (handling)", "")
filter = Replace(filter, "(handling)", "")
filter = Chr(34) + filter + Chr(34)
On Error Resume Next
myExplorer.Search filter, olSearchScopeAllFolders
If Err.Number <> 0 Then
MsgBox Err.Description
Err.Clear
myExplorer.Close
Exit Sub
End If
myExplorer.Display
End Sub
******************************
Any ideas?
TIA,