View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Michael Bednarek[_8_] Michael Bednarek[_8_] is offline
external usenet poster
 
Posts: 21
Default Run a dos batch file as soon as I exit/save the spreadsheet

On Fri, 8 Jul 2005 23:00:16 -0500, Chuckles123
wrote in
microsoft.public.excel.programming:

It's amazing! AFTER you pointed this out, your solution seems so
obvious. I will go into my office tomorrow and run it, but I am
confident it will work. Many THANKS!

A couple of questions:

- Why does the command prompt default to the ...\My Documents folder?


CMD.EXE is designed that way. I believe it establishes %HOMEDRIVE% and
%HOMEPATH% from the registry (HKLM\SOFTWARE\Microsoft\Windows
NT\CurrentVersion\ProfileList\{SID}\ProfileImagePa th) and that's where
it starts. You can change it on the fly by invoking it
CMD PUSHD d:\folder1\folder2 & mybatfile.cmd
or similar (e.g. with CD /D), but it is much better practice that a
batch file establish its current directory itself if it needs to.

- I am not positive, but I seemed to be getting identical results to
your code when I omitted the following characters: 'Environ("comspec")
& " /k " &'. Any comments? Also, when I was Googling, I saw that
several people were using 'Environ$("comspec")'. What does the '$' do
for them?


Dave Peterson already pointed out the purpose of Environ$().

As for using the environment variable COMSPEC: there is a very good
reason for it, as Microsoft OSs always allowed alternative command line
interpreters/shells. COMMAND.COM/CMD.EXE are just free samples of what a
real CLI might be - just as Notepad/Wordpad are free examples of proper
editors/word processors. The user's preferred CLI is known by inspecting
%COMPSPEC%.

As for omitting COMSPEC or CMD in the invokation altogether: you then
rely on the default action associated in the registry with .BAT or .CMD
files. In most systems, that association would be with CMD.EXE, but it
doesn't have to be - for security reasons it might well be with Notepad.

--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"