Shell & Windows Explorer search automation, and vbscript not found

M

Marceepoo

Discussions in Word Programming

vbscript not found, Shell & Windows Explorer search automation


The vbscript below works fairly well, but ...
1. I kind of feel that I'm cheating because the script relies on sendkeys,
because I can't find hooks to connect to the fields in the Windows Explorer
Search windows page. (I simplified the script; in practice, I feed the macro
different search paths and search filters, depending on the circumstances.)
Does anyone know where can I find info about automation and how to connect to
to those fields?


2. I can't figure out how to convert the script into vba code so that I
could run it as a macro. (nor could I figure out how to convert the script
into code that would run under visual studio 2008).


3. I tried to use the shell to call the script below, but vba returned a
message that I had used an invalid procedure call or argument:
Sub runFindFilesVbs()
Dim sRetVal As Integer
Dim strCmdLin As String 'chr(34)
strCmdLin =
"C:\Apps\Deeleet01\FindFilesVbScript_CommunitySolution.2008.05.28.vbs"
sRetVal = Shell(strCmdLin, 1) ' This line returned
' a message: Invalid procedure call or argument
End Sub


4. I tried to use the shell to run the following code (that works just fine
in a cmd window), but vba returned a message: File not found:

Sub runSearchBatCmdLin()
Dim sRetVal As String
Dim strCmdLin As String
strCmdLin = "type nul>mt.FND&start mt.FND&del /q /f /a mt.FND"
sRetVal = Shell(strCmdLin, 1) ' This line returned
' a message: File not found
End Sub

I'd be very grateful for any coding suggestions, or suggestions where I
could learn what I'm doing wrong, and what I need to do.

thanks,,,,,,,,,,,,,,,,,,,,,,,,,, marceepoo

Here's the scrpt that works just fine:

Dim objShell, WshShell
Set objShell = WScript.CreateObject("Shell.Application")
set WshShell = WScript.CreateObject("WScript.Shell")
objShell.FindFiles
WScript.Sleep 500
WshShell.AppActivate "Find: All files"
WScript.Sleep 2000
WshShell.SendKeys "%L"
WScript.Sleep 2000
WshShell.SendKeys "%L"
WScript.Sleep 2000
WshShell.SendKeys "k:\zmani"
WScript.Sleep 2000
WshShell.SendKeys "%o"
WScript.Sleep 1000
WshShell.SendKeys "%o"
WScript.Sleep 1000
WshShell.SendKeys "*.pdf"
WScript.Sleep 3000
WshShell.SendKeys "{enter}"

'Alt-O = Filename/filemask field, "All or part of the file name:",
' The Alt-O field is where you land in Windows Explorer, when
' you run the code lines above this comment.
'Alt-L = "Lookin in:" field
'Alt-R = "Search" button
 
S

Steve Yandl

A vbScript (vbs) file is not an executable file. The Shell function will
only launch an executable file. If you give it a non executable file, if
does not check the registry for the appropriate executable, it gives an
error instead. If you really want to run the vbs from inside a VBA routine,
have Shell launch either CScript.exe or WScript.exe using the path and
filename to your vbs as the argument.

Depending on the versions of Windows and Office you're working with and what
you actually want users to see, there are better approaches than having the
"Shell.Application" object run a Windows search. Without more details, I'll
just guess that a better approach would be to utilize Word's 'File > Open'
dialog to present the user with a set of filtered files from a designated
folder. As an alternate, you could run a vbs file but use the
"Scripting.FileSystemObject" object to select files. If the OS is WinXP,
you can grab a file search dialog with the filtered set of files using an
available XP user interface dialog. Provide a more specific example and
there will probably be several options available.


Steve Yandl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top