Re: Launch VBS from VBA

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thank you very much Chip.

You and Nick made my day!
--


Regards, Cajeto 63.





"Chip Pearson" wrote:

Import the module into your project. The "modShellAndWait" module is
entirely self-contained (as is "modShellAndWaitEnhanced"). You don't need to
change any code in that module.

To shell and wait for the Shell to end, just call the
F_7_AB_1_ShellAndWaitSimple function, passing to it the command line you
want Shell to execute. The F_7_AB_1_ShellAndWaitSimple function will call
Shell for you. So, all you have to do is

Dim Result As Boolean
Result = F_7_AB_1_ShellAndWaitSimple("WScript.exe
\\DellLapTop2\MainDrive\Test.vbs")
If Result = True Then
MsgBox "Shell'd program terminated successfully."
Else
MsgBox "There was an error."
End If

Note that there are certain system errors that will cause raise an error
than cannot be detected by VBA, and so under certain circumstances
F_7_AB_1_ShellAndWaitSimple will return True when an error occurred (these
are mostly network related errors).


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"Cajeto 63" <Cajeto63@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:2B6E5CD7-7E4C-4BAD-9796-D23EA958DD80@xxxxxxxxxxxxxxxx
Chip,
I have one last question for you,
I downloaded the self contained "modShellAndWaitSimple.bas" module but I
am
not sure how I integrate it to my code.

Shall I call the function before the Shell command or within the Shell
command and if so how or ???

Can you help?


--


Regards, Cajeto 63.





"Chip Pearson" wrote:

"NickHK" <TungCheWah@xxxxxxxxxxx> wrote in message

I can't test if they work with UNC paths

They do. E.g.,

Shell "WScript.exe \\DellLapTop2\MainDrive\Test.vbs"

If you need to wait for the script to finish before continuing with your
VBA
code, see http://www.cpearson.com/excel/shellandwait.htm for two
procedures,
ShellAndWaitSimple and ShellAndWaitEnhanced, that will cause your VBA
code
to wait until the Shell command completes before continuing.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"NickHK" <TungCheWah@xxxxxxxxxxx> wrote in message
news:OveZGOWCHHA.3448@xxxxxxxxxxxxxxxxxxxxxxx

Dim Retval
Retval = Shell("WScript.exe C:\Test.vbs")
or
Retval = Shell("CScript.exe C:\Test.vbs")

There is difference between the W and C script engines, but forget the
nuances now
I can't test if they work with UNC paths

NickHK

"Cajeto 63" <Cajeto63@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:888C8CE6-A69F-471B-9491-35ACF6442AA3@xxxxxxxxxxxxxxxx
Hello,

I'm trying to launch a VBS from excel using the code below:

Dim Retval
RetVal = Shell("cmd / u:\windows>u:\Formation\DataSet
Vision\VBscriptXL_Vision\ImportDonnéesTest.vbs")

but it does not work although the vbs works perfectly when launched
"by
hand"

Instead of running the script it opens a cmd windows giving the
following
message:
" CMD.EXE was started with the path "\\myserver\myname\my documents"
as
the
current directory. UNC paths are not supported. Defaulting to windows
directory."

Any help to solve this issue would be very highly appreciated.

Thank you.
--


Regards, Cajeto 63.











.



Relevant Pages

  • RE: Directories into arrays, again.
    ... >>> And a reason why using a shell command to copy a file is a bad idea. ... Well, I boiled the script down to essentials before posting it, ... only use the piped open form when you need to communicate ...
    (perl.beginners)
  • Re: Launch VBS from VBA
    ... To shell and wait for the Shell to end, ... Microsoft MVP - Excel ... Shall I call the function before the Shell command or within the Shell ... If you need to wait for the script to finish before continuing with your ...
    (microsoft.public.excel.programming)
  • Re: Shell Script
    ... Daffy D. wrote: ... I still have some problem with using Script files. ... The reason you're still in your old dir is that a shell script ... Any instruction that you write on a Shell command, ...
    (linux.redhat)
  • Re: How do I disable shell globbing in a script?
    ... > Unix/Linux and know nothing about shell globbing. ... > setting shell options like that. ... The best you can do if you can only modify the script (don't ... shell command line was used and this can't be done reliably. ...
    (comp.unix.shell)
  • Re: X = SHELL
    ... If you have no need for the return value of Shell (e.g., ... when the Shell'd program terminates), then the two are the same. ... Chip Pearson ... Microsoft Most Valuable Professional, ...
    (microsoft.public.excel.programming)