Running a Shell Command outside C Drive

Mang

Board Regular
Joined
Mar 17, 2005
Messages
62
Hi again everyone ...

The code thread below was originally suggested by our respected Mr Brian to solve part of my VBA problem in short-cutting the hyperlink "alert" messages.

But now I'm in the midst of trying to run my Excel VB from a portable device i.e a CD on a thumbdrive. And I have failed to get it running the same way as when it was running from my C drive though the Dos batch file is still being placed in the C drive.

I've tried to read the syntax in Dos Command Help file, but I find it a bit overwhelming for me to understand.

The piece of code is as below:

RSP = Shell(Environ$("COMSPEC") & " /c c:\myfolder\batch file\test.bat", vbNormalFocus)

Can anyone show me the light where have I gone wrong in trying to migrate my VB application from the C drive to a portable device i.e in running the above code.

I'm humbly appreciate all responds and suggestions from all of you.


Thank you.

- Mang -
 

Some videos you may like

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
You might get by with a small addition :-
Code:
ChDrive "C"
RSP = Shell(Environ$("COMSPEC") & " /c c:\myfolder\batch file\test.bat", vbNormalFocus)

The Environ$() bit is a fancy way of finding the DOS command file named CMD.EXE. If the above doesn't work you will need to find the file on your machine and put the full path. eg. on my system it's :-

Code:
RSP = Shell("C:\WINNT\System 32\cmd.exe" _
         & " /c c:\myfolder\batch file\test.bat", vbNormalFocus)
 

Mang

Board Regular
Joined
Mar 17, 2005
Messages
62
Shell Command

Thank you so much again, Mr Brian.

I shall try the suggested line of code in my codes. I bet that it will be working.

Anyhow, I would like to learn more about the "Comspec or shell command".

Is it possible for you to suggest to me a reference site or material that I can read?

FYI, I'm not an IT person, by education I'm suppose to be in the accounting profession, but currently am doing operations management. So thus all the hiccups....

Anyhow, thanks again and Happy New Year ...


- Mang -
 

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
I have to say that I have spent a lot of money on text books in the past and not found them wholly useful. OK for general groundwork I suppose.

Practically everything we need to know is on the web and can be found via a Google search. Excel Help is a good source, although, as in this case, not always complete.

Environ$("COMSPEC") is a VBA command. In the VB Editor code click Environ$ to put the cursor there, press F1 key.

Happy New Year to you too.
 

Watch MrExcel Video

Forum statistics

Threads
1,118,284
Messages
5,571,305
Members
412,380
Latest member
Angelagrace
Top