A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Macro for Instant Search in new Window, failes Instant search (OL2



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 3rd 09, 05:56 PM posted to microsoft.public.outlook.program_vba
Eylon
external usenet poster
 
Posts: 3
Default Macro for Instant Search in new Window, failes Instant search (OL2

Hello Everyone,

I wrote a Macro that takes the selected Email, removes some text from the
subject (e.g. “, 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(olF olderInbox),
olFolderDisplayNormal)

Dim filter As String

filter = email.Subject
filter = Replace(filter, " ", "")
filter = Replace(filter, "FW: ", "")
filter = Replace(filter, "", "")
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,

--
Eylon
  #2  
Old February 4th 09, 02:37 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Macro for Instant Search in new Window, failes Instant search (OL2

This runs in the Outlook VBA project? If so don't use New
Outlook.Application, use either Application or set app = Application. See if
that helps.

The error is a generic MAPI_E_COLLISION error, and that usually occurs if
you try to create a folder with the same name as another folder in the same
hierarchy location. So it's possible that displaying a new Explorer is
what's doing that and you might have to fall back on just using the existing
Explorer.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Eylon" wrote in message
...
Hello Everyone,

I wrote a Macro that takes the selected Email, removes some text from the
subject (e.g. “, 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(olF olderInbox),
olFolderDisplayNormal)

Dim filter As String

filter = email.Subject
filter = Replace(filter, " ", "")
filter = Replace(filter, "FW: ", "")
filter = Replace(filter, "", "")
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,

--
Eylon


  #3  
Old February 4th 09, 03:51 PM posted to microsoft.public.outlook.program_vba
Eylon
external usenet poster
 
Posts: 3
Default Macro for Instant Search in new Window, failes Instant search

Thanks Ken,
I run it from the Tools menu - Macro - Macros. Guess it makes it a VBA
project.
Tried your solution but it behaves the same (first time works, second
results in error, then must restart for normal GUI Instant search to work in
main window).

It does behave as expected if I run it from the GUI by right-clicking
Personal Folders in the Navigation Pane, Selectin Open in New Window, and
entering the search in the Instant Search box. With the macro I try to mimic
the same action.

Any other ideas?
Thanks again,
--
Eylon


"Ken Slovak - [MVP - Outlook]" wrote:

This runs in the Outlook VBA project? If so don't use New
Outlook.Application, use either Application or set app = Application. See if
that helps.

The error is a generic MAPI_E_COLLISION error, and that usually occurs if
you try to create a folder with the same name as another folder in the same
hierarchy location. So it's possible that displaying a new Explorer is
what's doing that and you might have to fall back on just using the existing
Explorer.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Eylon" wrote in message
...
Hello Everyone,

I wrote a Macro that takes the selected Email, removes some text from the
subject (e.g. “, 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(olF olderInbox),
olFolderDisplayNormal)

Dim filter As String

filter = email.Subject
filter = Replace(filter, " ", "")
filter = Replace(filter, "FW: ", "")
filter = Replace(filter, "", "")
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,

--
Eylon



  #4  
Old February 4th 09, 07:10 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Macro for Instant Search in new Window, failes Instant search

Only other idea would be to display the new Explorer before running Search
on it. Otherwise, no ideas other than using the original Explorer.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Eylon" wrote in message
...
Thanks Ken,
I run it from the Tools menu - Macro - Macros. Guess it makes it a VBA
project.
Tried your solution but it behaves the same (first time works, second
results in error, then must restart for normal GUI Instant search to work
in
main window).

It does behave as expected if I run it from the GUI by right-clicking
Personal Folders in the Navigation Pane, Selectin Open in New Window, and
entering the search in the Instant Search box. With the macro I try to
mimic
the same action.

Any other ideas?
Thanks again,
--
Eylon

  #5  
Old February 5th 09, 08:44 AM posted to microsoft.public.outlook.program_vba
Eylon
external usenet poster
 
Posts: 3
Default Macro for Instant Search in new Window, failes Instant search

Thanks again Ken,
Displaying before did not help.

Anyone else have any ideas?

--
Eylon


"Ken Slovak - [MVP - Outlook]" wrote:

Only other idea would be to display the new Explorer before running Search
on it. Otherwise, no ideas other than using the original Explorer.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Instant Search, Advanced Find, Search Folders, and Windows Desktop [email protected] Outlook - General Queries 2 October 31st 08 06:37 PM
Instant Search? Candy Outlook - General Queries 6 January 24th 08 08:45 PM
SPEED: Instant Search vs. Search Folders [email protected] Outlook - General Queries 0 November 21st 07 03:18 PM
Instant Search - Brenda Outlook - General Queries 1 August 7th 07 11:23 AM
2007 search box and instant search invite, remove them jeffrey Outlook - General Queries 2 February 28th 07 04:08 PM


All times are GMT +1. The time now is 12:25 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright 2004-2025 Outlook Banter.
The comments are property of their posters.