从VBA,在资源管理器中的指定文件夹中运行搜索 [英] from VBA, run a search in explorer within a designated folder
问题描述
我是VBA的新手,正在做一些工作,这些工作将在资源管理器中启动给定的文件夹,在资源管理器中搜索该文件夹中名称包含特定字符串的文件,并在资源管理器中显示结果.我一直在使用shell,并且能够单独打开一个特定的文件夹并运行搜索...但是我不知道如何同时执行这两个任务.
I'm relatively new to VBA and working on something for work that will launch a given folder in explorer, run a search in explorer for files in that folder whose names contain a certain string, and show me the results in explorer. I've been using shell, and was able to individually open a specific folder, and run a search...but I can't figure out how to do both tasks simultaneously.
这是我尝试过的一些不同的事情:没有任何效果.
Here's some different things I've tried: nothing has worked.
Sub search_Files()
Dim folderName As String
folderName = "\\Users\itsMe\Documents"
Call Shell("C:\WINDOWS\explorer.exe "" "" & folderName _
&"" ""&search-ms://query=h&", vbNormalFocus)
Call Shell("explorer.exe "" ""search-ms:query=h&crumb=location:\\Users\itsMe\Documents", vbNormalFocus)
Call Shell("C:\WINDOWS\explorer.exe"" & FolderName &", vbNormalFocus)
RetVal = Shell( _
"c:\Windows\explorer.exe ""search-ms:displayname=Search%20Results&crumb=\\Users\itsMe\Documents" _
& h & "%20kind%3A%3Dfolder&crumb=location:" _
& folderName, vbNormalFocus)
End Sub
有人可以为我提供有关如何执行此操作的正确代码吗? (我想使用外壳.)
Could someone please provide me with the proper code on how to do this? (I want to use shell.)
推荐答案
您是说您的代码需要替换下面的第五个代码?我已经尝试修改相关的目标文件夹.但是仍然失败.不确定在哪一步做错了.
Do you mean your code need to replace the fifth one as below? I am tried to modify the related destination folder already. But still fail. Not sure I did wrong in which step.
Sub search_Files()
Dim folderName As String
folderName = "C:\Users\lkam\Documents"
Call Shell("C:\WINDOWS\explorer.exe "" "" & folderName _
&"" ""&search-ms://query=h&", vbNormalFocus)
Call Shell("explorer.exe " & Chr(34) & "search-ms:query=*.pdf&crumb=location:c:\ad\" & Chr(34), vbNormalFocus)
Call Shell("C:\WINDOWS\explorer.exe"" & FolderName &", vbNormalFocus)
RetVal = Shell( _
"c:\Windows\explorer.exe ""search-ms:displayname=Search%20Results&crumb=C:\Users\lkam\Documents" _
& h & "%20kind%3A%3Dfolder&crumb=location:" _
& folderName, vbNormalFocus)
End Sub
这篇关于从VBA,在资源管理器中的指定文件夹中运行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!