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 -
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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)
 
Upvote 0
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 -
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,085
Members
449,064
Latest member
MattDRT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top