Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Supress code while command is being executed 2

Status
Not open for further replies.

CooterBrown

IS-IT--Management
Aug 17, 2001
125
0
0
US
How do I suppress the code while a shell command is being executed.

Shell "C:\Program Files\IBM\Client Access\cwbtf.exe " & gstrAppPath & "\TestQryOut2.tto", vbHide
 
, True" for the wait parameters of your Shell command
 
It's only asking me for two parameters: Path Name and Windows Style...which I have as vbHide
 
If the Shell function successfully executes the named file, it returns the task ID of the started program. The task ID is a unique number that identifies the running program. If the Shell function can't start the named program, an error occurs.

On the Macintosh, vbNormalFocus, vbMinimizedFocus, and vbMaximizedFocus all place the application in the foreground; vbHide, vbNoFocus, vbMinimizeFocus all place the application in the background.

Note By default, the Shell function runs other programs asynchronously. This means that a program started with Shell might not finish executing before the statements following the Shell function are executed.


'so looks like you need to keep an eye on the progress of the ID that is started
'or you could cheat and use
Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run "c:\notepad.exe", 1, True

where 1 is the window style and True is to wait for the thread to terminate..
 
Method Run of Object "IWshShell3" failed...

Do I need a reference?
 
shouldnt do.
are you trying

WshShell.Run "c:\notepad.exe", 1, True

sorry but that was a rubbish example as you would get an error cause notepad.exe isnt located in the root of c:

seeing as you are getting "IWshShell3" does that imply that this is the third reference to a Wscript.Shell object in your code?

how about this

Msgbox WshShell.ExpandEnvironmentStrings("%username%")
 
I realized that about NotePad.exe

Here's my routine below. I think the error occurs because of the complex command that I'm trying to shell with an executable and a parameter.

Dim WShShell As Object
Dim pathToRun
Set WShShell = CreateObject("Wscript.Shell")

'build path
pathToRun = "C:\Program Files\IBM\Client Access\cwbtf.exe " & gstrAppPath & "\TestQryOut2.tto"


WShShell.Run pathToRun, 1, True



I'm only referencing Wscript.shell object one other time previously in the code... I'm setting it to Nothing when finished.
 
See PHV's posting on the use of quotation marks for the command line string at thread thread707-952388


Regards,
Mike
 
Thanks but I still can't get this command to work!

gstrAppPath = "C:\Directory"

WShShell.Run """C:\Program Files\IBM\Client Access\cwbtf.exe " & gstrAppPath & "\TestQryOut2.tto""", 1, True
 
Give the Chr(34)'s around the path string at try. Folder names with spaces seem to be a problem otherwise.

Mike
 
WShShell.Run """C:\Program Files\IBM\Client Access\cwbtf.exe"" """ & gstrAppPath & "\TestQryOut2.tto""", 1, True

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PHV to the rescue! [thumbsup]

In my mock-up (using notepad & a text file), the following error'd out:
Code:
strPath = "C:\Dummy Folder\"
WShShell.Run strPath &"notepad.exe " & strPath &"MyTextfile.txt"

but this didn't:
Code:
strPath = "C:\Dummy Folder\"
WShShell.Run Chr(34) & strPath &"notepad.exe " &Chr(34) & strPath &"MyTextfile.txt"


Regards,
Mike
 
Thanks for all of the help...I finally nailed it thanks to rmikesmith & PHV! Too many Chr(34)'s in that string!



Private Sub TransferFile()

Dim WShShell As Object
Set WShShell = CreateObject("Wscript.Shell")

WShShell.Run Chr(34) & "C:\Program Files\IBM\Client Access\cwbtf.exe " & Chr(34) & gstrAppPath & "\TestQryOut2.tto", 1, True

End Sub
 
Glad you got it working.

Doesn't seem fair that the computer couldn't care less whether you've written a page-full of garbage or a single character out of place.


Regards,
Mike
 
so you didnt use Wscript.Shell in the solution then?
 
sorry i will re-phrase 'adding quotation marks to a command line string means that code is suppressed while a command is being executed'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top