Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Launch VBS from VBA

Hello,

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

Dim Retval
RetVal = Shell("cmd / u:\windowsu:\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.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Launch VBS from VBA


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" wrote in message
...
Hello,

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

Dim Retval
RetVal = Shell("cmd / u:\windowsu:\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.





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Launch VBS from VBA

"NickHK" 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" wrote in message
...

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" wrote in message
...
Hello,

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

Dim Retval
RetVal = Shell("cmd / u:\windowsu:\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.







  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Launch VBS from VBA

Thank you Chip,
I did not think about it but the material I downloaded from your site will
be very helpfull (although it seems quite complicated for a newbie like me at
a first glance :-)


--


Regards, Cajeto 63.





"Chip Pearson" wrote:

"NickHK" 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" wrote in message
...

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" wrote in message
...
Hello,

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

Dim Retval
RetVal = Shell("cmd / u:\windowsu:\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.








  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Launch VBS from VBA

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" 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" wrote in message
...

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" wrote in message
...
Hello,

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

Dim Retval
RetVal = Shell("cmd / u:\windowsu:\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.










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Launch VBS from VBA

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" wrote in message
...
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" 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" wrote in message
...

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" wrote in message
...
Hello,

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

Dim Retval
RetVal = Shell("cmd / u:\windowsu:\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.










  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Launch VBS from VBA

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" wrote in message
...
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" 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" wrote in message
...

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" wrote in message
...
Hello,

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

Dim Retval
RetVal = Shell("cmd / u:\windowsu:\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.











  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 26
Default Launch VBS from VBA

Thank you very much Nick.

It works perfectly with the WScript and I'll keep in mind that a CScript
exists just in case.


--


Regards, Cajeto 63.





"NickHK" wrote:


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" wrote in message
...
Hello,

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

Dim Retval
RetVal = Shell("cmd / u:\windowsu:\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.






  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Launch VBS from VBA

You need to instantiate a shell object. Try something like;

Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd /K CD C:\ & Dir"
Set oShell = Nothing

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"Cajeto 63" wrote:
| Hello,
|
| I'm trying to launch a VBS from excel using the code below:
|
| Dim Retval
| RetVal = Shell("cmd / u:\windowsu:\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.
|
|
|


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default Launch VBS from VBA

Oops, should have been;

Dim oShell
Set oShell = CreateObject ("WSCript.shell")
oShell.run "cmd /K CD C:\ & Dir"
Set oShell = Nothing

--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect




  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Launch VBS from VBA

i do one of these
a prior macro introduces the "connected " to display that i was able to net
use to the workstation
retval = Shell("cmd /c C:\scriptname.vbs " & Replace(c.Value, "connected ",
""), vbMaximizedFocus)

"Cajeto 63" wrote:

Hello,

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

Dim Retval
RetVal = Shell("cmd / u:\windowsu:\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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add-In Launch MimiS Excel Discussion (Misc queries) 0 May 18th 10 08:42 PM
Error msg on launch KateSeidel Excel Discussion (Misc queries) 3 March 4th 09 08:11 PM
File won't launch eric blom Excel Discussion (Misc queries) 1 September 17th 07 10:30 PM
How to launch one XLA from another on Excel launch levka Excel Programming 1 July 25th 05 04:22 AM
Macro launch - Button vs Manual launch , has different results. Wayne Excel Programming 4 February 23rd 05 11:33 AM


All times are GMT +1. The time now is 08:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"