Takamine334
asked on
Help with Macro to customize search
Does anyone know of a macro that I can use that will customize a search on the SENT ITEMS folder? I need it to read from the clipboard. So, it'd be something like this:
1. CTRL-C an email address in the text of the email message body
2. Hit a HOTKEY invoking the Macro
3. The macro will search the SENT ITEMS folder with the clipboard.settext function
4. The macro will return a value showing if the email on the clipboard is located in the SENT ITEMS folder.
1. CTRL-C an email address in the text of the email message body
2. Hit a HOTKEY invoking the Macro
3. The macro will search the SENT ITEMS folder with the clipboard.settext function
4. The macro will return a value showing if the email on the clipboard is located in the SENT ITEMS folder.
ASKER
1. I would want to see the match if it occurs
2. I would like to see if the match occurs in the TO text box.
2. I would like to see if the match occurs in the TO text box.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
First off, I think you should be given the Mensa Award.
Now that that's said, I highlighted and copied an email address in a message. I ran the macro and it pulled up:
Results of Search Search1
There were 1 matches.
NACA Question
When I clicked on the link, nothing happened. Can you tell me if I'm doing something wrong?
Now that that's said, I highlighted and copied an email address in a message. I ran the macro and it pulled up:
Results of Search Search1
There were 1 matches.
NACA Question
When I clicked on the link, nothing happened. Can you tell me if I'm doing something wrong?
ASKER
Actually, another IE window appeared with the URL:
outlook:00000000D2BB204E2A D386469DE6 3453C260EE 8EA4882300
The page said:
The webpage cannot be displayed
Most likely cause:
Some content or files on this webpage require a program that you don't have installed.
What you can try:
Search online for a program you can use to view this web content.
Retype the address.
Go back to the previous page.
outlook:00000000D2BB204E2A
The page said:
The webpage cannot be displayed
Most likely cause:
Some content or files on this webpage require a program that you don't have installed.
What you can try:
Search online for a program you can use to view this web content.
Retype the address.
Go back to the previous page.
ASKER
Also, I'm getting the below response when using this macro. Is there anyway to just open up the SENT ITEMS folder that stores this email?
Clipboard01.gif
Clipboard01.gif
Thanks for the thought.
You aren't doing anything wrong. By default Office/Outlook 2007 does not install a URL protocol handler for links to Outlook items. The protocol handler is just a couple of registry entries. There's an explanation and .reg file download tht'll add the entries for you at this page: http://www.davidtan.org/outlook-2007-adding-outlook-url-protocol/ After applying the .reg file you may have to edit the entries. Go ahead and install the .reg file, then try a one of the links and let me know what happens.
You aren't doing anything wrong. By default Office/Outlook 2007 does not install a URL protocol handler for links to Outlook items. The protocol handler is just a couple of registry entries. There's an explanation and .reg file download tht'll add the entries for you at this page: http://www.davidtan.org/outlook-2007-adding-outlook-url-protocol/ After applying the .reg file you may have to edit the entries. Go ahead and install the .reg file, then try a one of the links and let me know what happens.
ASKER
Absolutely perfect. Would it be possible to put this command in a (right click) menu link?
1. Select hyperlink
2. ALT+F8
3. Select THISOUTLOOKSESSION.MYSEARC H
1. Select hyperlink
2. ALT+F8
3. Select THISOUTLOOKSESSION.MYSEARC
ASKER
Once again, BlueDevil rocked it!
The dialog-box you took the screenshot of is generated when reading data from the clipboard. Try replacing MySearch with the version below. You'll need to add a reference to FM20.DLL in Outlook. To do that
- Open the VB editor in Outlook
- Click Tools > References
- Click the Browse button
- Go to the Windows System32 folder
- Find and add FM20.DLL
Sub MySearch()
Const strScope As String = "'Sent Items'"
Const strTag As String = "Search1"
Dim objData As New DataObject, _
olkSearch As Outlook.Search, _
strFilter As String, _
strBuffer As String
objData.GetFromClipboard
strBuffer = objData.GetText()
strFilter = "urn:schemas:httpmail:displayto LIKE '%" & varText & "%'"
Set objSch = Application.AdvancedSearch(Scope:=strScope, Filter:=strFilter, SearchSubFolders:=False, Tag:=strTag)
End Sub
ASKER
Did the above and the error is gone, however, when searching an email I get:
Results of Search Search1
There were 0 matches.
I'm actually looking at the SENT ITEMS folder that does contain that email.
Results of Search Search1
There were 0 matches.
I'm actually looking at the SENT ITEMS folder that does contain that email.
Oops. Typo. Disregard that last version and use this one instead.
Sub MySearch()
Const strScope As String = "'Sent Items'"
Const strTag As String = "Search1"
Dim objData As New DataObject, _
olkSearch As Outlook.Search, _
strFilter As String, _
strBuffer As String
objData.GetFromClipboard
strBuffer = objData.GetText()
strFilter = "urn:schemas:httpmail:displayto LIKE '%" & strBuffer & "%'"
Set objSch = Application.AdvancedSearch(Scope:=strScope, Filter:=strFilter, SearchSubFolders:=False, Tag:=strTag)
End Sub
I'll work on the context menu angle.
ASKER
I see that varText = Empty
ASKER
Changed varText to strBuffer and it works.
ASKER
Would it be possible to put this command in a (right click) menu link?
1. Select hyperlink
2. ALT+F8
3. Select THISOUTLOOKSESSION.MYSEARC H
1. Select hyperlink
2. ALT+F8
3. Select THISOUTLOOKSESSION.MYSEARC
The right-click, "context", menus in Outlook are separate entities. Do you want this added to all of them or only one? If one, which one?
ASKER
I'm sorry, I don't understand the question.
No problem. Te right-click menus in Outlook are called "context" menus. The selections offered on a menu are in the "context" of the click. For example, right-clicking on a folder displays selections that apply to a folder context. Right-clicking on a message displays selections in the context of a message. Outlook defines the following six contexts: Attachment, Folder, Item, ShortCut Store, and View. My question is whether you want a menu selection added to all of them, some of them, or only one of them? In other words, do you want the search option to appear when you right-click on an attachment, a folder, a vew, etc? Unfortunately the context menu that appears when you right-click on an address isn't programmable.
ASKER
I see. Thank you for that information. I would assume I'd only need that function when I right click an email when viewing emails in the preview pane or when they are double clicked and the email message is in its own form.
Sorry to be slow getting back to you. None of the context menus work in open items. Are you sure you wouldn't prefer a toolbar button?
ASKER
A button would work fine. Thank you.
Apologies again for being so slow. Here's how to add a toolbar and button for running a given macro.
1. Click View->Toolbars->Customize
2. Click the Toolbars tab
3. Click New
4. Name the toolbar
5. Click the Commands tab
6. Under Categories click Macros
7. Under Commands click and hold on the macro, then drag it out and drop it on the new toolbar
8. Dock the toolbar somewhere onscreen
1. Click View->Toolbars->Customize
2. Click the Toolbars tab
3. Click New
4. Name the toolbar
5. Click the Commands tab
6. Under Categories click Macros
7. Under Commands click and hold on the macro, then drag it out and drop it on the new toolbar
8. Dock the toolbar somewhere onscreen
A couple of questions.