Windows Explorer tag search

Snazzy D

New Member
Joined
Mar 13, 2019
Messages
1
I would like to set up a link from a cell to open an Explorer window and search for tags that match the cell's contents.
An example would be:

1. Click a cell that reads "Golf".
2. An Explorer window opens and automatically searches for any files tagged with the word "Golf".

I already have a link to open the Explorer window, but I would like it to do an automatic search for me.
There are 4 people in my office that would use this a lot, and it would be much easier than opening an Explorer window and typing "tag:golf" in the search box.
(Especially since some of the tags are rather long, like "porte cochere"!)

Thanks for any suggestions!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I know this is way late, but I was looking to do something similar. After a lot of searching, I was able to modify some code I found online that would do what we needed. The first Sub "ShowSearch" seems to run the actual process of opening explorer and searching while the second Sub "SearchEngine" defines the location and what you want to search for. The 3rd sub "CloseWIndow" closes instances of "Explorer.exe" because I found that if I already had the file explorer up, it wouldn't run properly. Hope this isn't too late to be helpful.

VBA Code:
Sub ShowSearch(searchWhere, searchFor, Optional SearchByKeyword As Boolean = False)
    Const CMD As String = "explorer.exe ""search-ms:crumb=name:{query}&crumb=location:{location}"" "
    Dim s
    s = Replace(CMD, "{query}", WorksheetFunction.EncodeURL(searchFor))
    s = Replace(s, "{location}", WorksheetFunction.EncodeURL(searchWhere))
    If SearchByKeyword Then s = Replace(s, "crumb=name:", "crumb=")
    'Debug.Print s
    Shell s
End Sub

Sub SearchEngine()
Dim filesearch As String
Dim tagname As String
Dim tagsearch As String

filesearch = "put your file location here"
tagname = Sheet1.Range("A1").Text  'replace with wherever you type "golf"
tagsearch = "tags:" & Chr(34) & tagname & Chr(34)

Call CloseWindow
ShowSearch filesearch, tagsearch, True


End Sub

Sub CloseWindow()

    Dim objWMIcimv2 As Object, objProcess As Object, objList As Object
    Dim intError As Integer

    Set objWMIcimv2 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set objList = objWMIcimv2.ExecQuery("select * from win32_process where name='explorer.exe'")

    For Each objProcess In objList
        intError = objProcess.Terminate
        If intError <> 0 Then Exit For
    Next

    Set objWMIcimv2 = Nothing
    Set objList = Nothing
    Set objProcess = Nothing
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top